<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html lang="en">

<head>
  <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
  <title>LCOV - self_test2.info - network_io/unix/sendrecv.c</title>
  <link rel="stylesheet" type="text/css" href="../../gcov.css">
</head>

<body>

  <table width="100%" border=0 cellspacing=0 cellpadding=0>
    <tr><td class="title">LCOV - code coverage report</td></tr>
    <tr><td class="ruler"><img src="../../glass.png" width=3 height=3 alt=""></td></tr>

    <tr>
      <td width="100%">
        <table cellpadding=1 border=0 width="100%">
          <tr>
            <td width="10%" class="headerItem">Current view:</td>
            <td width="35%" class="headerValue"><a href="../../index.html">top level</a> - <a href="index.html">network_io/unix</a> - sendrecv.c<span style="font-size: 80%;"> (source / <a href="sendrecv.c.func.html">functions</a>)</span></td>
            <td width="5%"></td>
            <td width="15%"></td>
            <td width="10%" class="headerCovTableHead">Hit</td>
            <td width="10%" class="headerCovTableHead">Total</td>
            <td width="15%" class="headerCovTableHead">Coverage</td>
          </tr>
          <tr>
            <td class="headerItem">Test:</td>
            <td class="headerValue">self_test2.info</td>
            <td></td>
            <td class="headerItem">Lines:</td>
            <td class="headerCovTableEntry">43</td>
            <td class="headerCovTableEntry">161</td>
            <td class="headerCovTableEntryLo">26.7 %</td>
          </tr>
          <tr>
            <td class="headerItem">Date:</td>
            <td class="headerValue">2011-07-03</td>
            <td></td>
            <td class="headerItem">Functions:</td>
            <td class="headerCovTableEntry">4</td>
            <td class="headerCovTableEntry">6</td>
            <td class="headerCovTableEntryLo">66.7 %</td>
          </tr>
          <tr>
            <td></td>
            <td></td>
            <td></td>
            <td class="headerItem">Branches:</td>
            <td class="headerCovTableEntry">31</td>
            <td class="headerCovTableEntry">160</td>
            <td class="headerCovTableEntryLo">19.4 %</td>
          </tr>
          <tr><td><img src="../../glass.png" width=3 height=3 alt=""></td></tr>
        </table>
      </td>
    </tr>

    <tr><td class="ruler"><img src="../../glass.png" width=3 height=3 alt=""></td></tr>
  </table>

  <table cellpadding=0 cellspacing=0 border=0>
    <tr>
      <td><br></td>
    </tr>
    <tr>
      <td>
<pre class="sourceHeading">           Branch data     Line data    Source code</pre>
<pre class="source">
<a name="1"><span class="lineNum">       1 </span>                :            : /* Licensed to the Apache Software Foundation (ASF) under one or more</a>
<span class="lineNum">       2 </span>                :            :  * contributor license agreements.  See the NOTICE file distributed with
<span class="lineNum">       3 </span>                :            :  * this work for additional information regarding copyright ownership.
<span class="lineNum">       4 </span>                :            :  * The ASF licenses this file to You under the Apache License, Version 2.0
<span class="lineNum">       5 </span>                :            :  * (the &quot;License&quot;); you may not use this file except in compliance with
<span class="lineNum">       6 </span>                :            :  * the License.  You may obtain a copy of the License at
<span class="lineNum">       7 </span>                :            :  *
<span class="lineNum">       8 </span>                :            :  *     http://www.apache.org/licenses/LICENSE-2.0
<span class="lineNum">       9 </span>                :            :  *
<span class="lineNum">      10 </span>                :            :  * Unless required by applicable law or agreed to in writing, software
<span class="lineNum">      11 </span>                :            :  * distributed under the License is distributed on an &quot;AS IS&quot; BASIS,
<span class="lineNum">      12 </span>                :            :  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
<span class="lineNum">      13 </span>                :            :  * See the License for the specific language governing permissions and
<span class="lineNum">      14 </span>                :            :  * limitations under the License.
<span class="lineNum">      15 </span>                :            :  */
<span class="lineNum">      16 </span>                :            : 
<span class="lineNum">      17 </span>                :            : #include &quot;apr_arch_networkio.h&quot;
<span class="lineNum">      18 </span>                :            : #include &quot;apr_support.h&quot;
<span class="lineNum">      19 </span>                :            : 
<span class="lineNum">      20 </span>                :            : #if APR_HAS_SENDFILE
<span class="lineNum">      21 </span>                :            : /* This file is needed to allow us access to the apr_file_t internals. */
<span class="lineNum">      22 </span>                :            : #include &quot;apr_arch_file_io.h&quot;
<span class="lineNum">      23 </span>                :            : #endif /* APR_HAS_SENDFILE */
<span class="lineNum">      24 </span>                :            : 
<span class="lineNum">      25 </span>                :            : /* osreldate.h is only needed on FreeBSD for sendfile detection */
<span class="lineNum">      26 </span>                :            : #if defined(__FreeBSD__)
<span class="lineNum">      27 </span>                :            : #include &lt;osreldate.h&gt;
<span class="lineNum">      28 </span>                :            : #endif
<span class="lineNum">      29 </span>                :            : 
<a name="30"><span class="lineNum">      30 </span>                :            : apr_status_t apr_socket_send(apr_socket_t *sock, const char *buf, </a>
<span class="lineNum">      31 </span>                :            :                              apr_size_t *len)
<span class="lineNum">      32 </span>                :<span class="lineCov">          3 : {</span>
<span class="lineNum">      33 </span>                :            :     apr_ssize_t rv;
<span class="lineNum">      34 </span>                :            :     
<span class="lineNum">      35 </span>        [<span class="branchNoCov" title="Branch 0 was not taken"> - </span><span class="branchCov" title="Branch 1 was taken 3 times"> + </span>]:<span class="lineCov">          3 :     if (sock-&gt;options &amp; APR_INCOMPLETE_WRITE) {</span>
<span class="lineNum">      36 </span>                :<span class="lineNoCov">          0 :         sock-&gt;options &amp;= ~APR_INCOMPLETE_WRITE;</span>
<span class="lineNum">      37 </span>                :<span class="lineNoCov">          0 :         goto do_select;</span>
<span class="lineNum">      38 </span>                :            :     }
<span class="lineNum">      39 </span>                :            : 
<span class="lineNum">      40 </span>                :            :     do {
<span class="lineNum">      41 </span>                :<span class="lineCov">          3 :         rv = write(sock-&gt;socketdes, buf, (*len));</span>
<span class="lineNum">      42 </span>[<span class="branchNoCov" title="Branch 0 was not taken"> - </span><span class="branchCov" title="Branch 1 was taken 3 times"> + </span>][<span class="branchNoExec" title="Branch 3 was not executed"> # </span><span class="branchNoExec" title="Branch 4 was not executed"> # </span>]:<span class="lineCov">          3 :     } while (rv == -1 &amp;&amp; errno == EINTR);</span>
<span class="lineNum">      43 </span>                :            : 
<span class="lineNum">      44 </span>[<span class="branchNoCov" title="Branch 0 was not taken"> - </span><span class="branchCov" title="Branch 1 was taken 3 times"> + </span>][<span class="branchNoExec" title="Branch 3 was not executed"> # </span><span class="branchNoExec" title="Branch 4 was not executed"> # </span>]:<span class="lineCov">          3 :     while (rv == -1 &amp;&amp; (errno == EAGAIN || errno == EWOULDBLOCK) </span>
<span class="lineNum">         </span>        [<span class="branchNoExec" title="Branch 5 was not executed"> # </span><span class="branchNoExec" title="Branch 6 was not executed"> # </span>]
<span class="lineNum">      45 </span>                :            :                     &amp;&amp; (sock-&gt;timeout &gt; 0)) {
<span class="lineNum">      46 </span>                :            :         apr_status_t arv;
<span class="lineNum">      47 </span>                :<span class="lineNoCov">          0 : do_select:</span>
<span class="lineNum">      48 </span>                :<span class="lineNoCov">          0 :         arv = apr_wait_for_io_or_timeout(NULL, sock, 0);</span>
<span class="lineNum">      49 </span>        [<span class="branchNoExec" title="Branch 0 was not executed"> # </span><span class="branchNoExec" title="Branch 1 was not executed"> # </span>]:<span class="lineNoCov">          0 :         if (arv != APR_SUCCESS) {</span>
<span class="lineNum">      50 </span>                :<span class="lineNoCov">          0 :             *len = 0;</span>
<span class="lineNum">      51 </span>                :<span class="lineNoCov">          0 :             return arv;</span>
<span class="lineNum">      52 </span>                :            :         }
<span class="lineNum">      53 </span>                :            :         else {
<span class="lineNum">      54 </span>                :            :             do {
<span class="lineNum">      55 </span>                :<span class="lineNoCov">          0 :                 rv = write(sock-&gt;socketdes, buf, (*len));</span>
<span class="lineNum">      56 </span>[<span class="branchNoExec" title="Branch 0 was not executed"> # </span><span class="branchNoExec" title="Branch 1 was not executed"> # </span>][<span class="branchNoExec" title="Branch 3 was not executed"> # </span><span class="branchNoExec" title="Branch 4 was not executed"> # </span>]:<span class="lineNoCov">          0 :             } while (rv == -1 &amp;&amp; errno == EINTR);</span>
<span class="lineNum">      57 </span>                :            :         }
<span class="lineNum">      58 </span>                :            :     }
<span class="lineNum">      59 </span>        [<span class="branchNoCov" title="Branch 0 was not taken"> - </span><span class="branchCov" title="Branch 1 was taken 3 times"> + </span>]:<span class="lineCov">          3 :     if (rv == -1) {</span>
<span class="lineNum">      60 </span>                :<span class="lineNoCov">          0 :         *len = 0;</span>
<span class="lineNum">      61 </span>                :<span class="lineNoCov">          0 :         return errno;</span>
<span class="lineNum">      62 </span>                :            :     }
<span class="lineNum">      63 </span>[<span class="branchCov" title="Branch 0 was taken 2 times"> + </span><span class="branchCov" title="Branch 1 was taken 1 time"> + </span>][<span class="branchNoCov" title="Branch 2 was not taken"> - </span><span class="branchCov" title="Branch 3 was taken 2 times"> + </span>]:<span class="lineCov">          3 :     if ((sock-&gt;timeout &gt; 0) &amp;&amp; (rv &lt; *len)) {</span>
<span class="lineNum">      64 </span>                :<span class="lineNoCov">          0 :         sock-&gt;options |= APR_INCOMPLETE_WRITE;</span>
<span class="lineNum">      65 </span>                :            :     }
<span class="lineNum">      66 </span>                :<span class="lineCov">          3 :     (*len) = rv;</span>
<span class="lineNum">      67 </span>                :<span class="lineCov">          3 :     return APR_SUCCESS;</span>
<span class="lineNum">      68 </span>                :            : }
<a name="69"><span class="lineNum">      69 </span>                :            : </a>
<span class="lineNum">      70 </span>                :            : apr_status_t apr_socket_recv(apr_socket_t *sock, char *buf, apr_size_t *len)
<span class="lineNum">      71 </span>                :<span class="lineCov">          4 : {</span>
<span class="lineNum">      72 </span>                :            :     apr_ssize_t rv;
<span class="lineNum">      73 </span>                :            :     apr_status_t arv;
<span class="lineNum">      74 </span>                :            : 
<span class="lineNum">      75 </span>        [<span class="branchNoCov" title="Branch 0 was not taken"> - </span><span class="branchCov" title="Branch 1 was taken 4 times"> + </span>]:<span class="lineCov">          4 :     if (sock-&gt;options &amp; APR_INCOMPLETE_READ) {</span>
<span class="lineNum">      76 </span>                :<span class="lineNoCov">          0 :         sock-&gt;options &amp;= ~APR_INCOMPLETE_READ;</span>
<span class="lineNum">      77 </span>                :<span class="lineNoCov">          0 :         goto do_select;</span>
<span class="lineNum">      78 </span>                :            :     }
<span class="lineNum">      79 </span>                :            : 
<span class="lineNum">      80 </span>                :            :     do {
<span class="lineNum">      81 </span>                :<span class="lineCov">          8 :         rv = read(sock-&gt;socketdes, buf, (*len));</span>
<span class="lineNum">      82 </span>[<span class="branchCov" title="Branch 0 was taken 1 time"> + </span><span class="branchCov" title="Branch 1 was taken 3 times"> + </span>][<span class="branchNoCov" title="Branch 3 was not taken"> - </span><span class="branchCov" title="Branch 4 was taken 1 time"> + </span>]:<span class="lineCov">          4 :     } while (rv == -1 &amp;&amp; errno == EINTR);</span>
<span class="lineNum">      83 </span>                :            : 
<span class="lineNum">      84 </span>[<span class="branchCov" title="Branch 0 was taken 1 time"> + </span><span class="branchCov" title="Branch 1 was taken 3 times"> + </span>][<span class="branchCov" title="Branch 3 was taken 1 time"> + </span><span class="branchNoCov" title="Branch 4 was not taken"> - </span>]:<span class="lineCov">          4 :     while ((rv == -1) &amp;&amp; (errno == EAGAIN || errno == EWOULDBLOCK)</span>
<span class="lineNum">         </span>        [<span class="branchCov" title="Branch 5 was taken 1 time"> + </span><span class="branchNoCov" title="Branch 6 was not taken"> - </span>]
<span class="lineNum">      85 </span>                :            :                       &amp;&amp; (sock-&gt;timeout &gt; 0)) {
<span class="lineNum">      86 </span>                :<span class="lineCov">          1 : do_select:</span>
<span class="lineNum">      87 </span>                :<span class="lineCov">          1 :         arv = apr_wait_for_io_or_timeout(NULL, sock, 1);</span>
<span class="lineNum">      88 </span>        [<span class="branchCov" title="Branch 0 was taken 1 time"> + </span><span class="branchNoCov" title="Branch 1 was not taken"> - </span>]:<span class="lineCov">          1 :         if (arv != APR_SUCCESS) {</span>
<span class="lineNum">      89 </span>                :<span class="lineCov">          1 :             *len = 0;</span>
<span class="lineNum">      90 </span>                :<span class="lineCov">          1 :             return arv;</span>
<span class="lineNum">      91 </span>                :            :         }
<span class="lineNum">      92 </span>                :            :         else {
<span class="lineNum">      93 </span>                :            :             do {
<span class="lineNum">      94 </span>                :<span class="lineNoCov">          0 :                 rv = read(sock-&gt;socketdes, buf, (*len));</span>
<span class="lineNum">      95 </span>[<span class="branchNoExec" title="Branch 0 was not executed"> # </span><span class="branchNoExec" title="Branch 1 was not executed"> # </span>][<span class="branchNoExec" title="Branch 3 was not executed"> # </span><span class="branchNoExec" title="Branch 4 was not executed"> # </span>]:<span class="lineNoCov">          0 :             } while (rv == -1 &amp;&amp; errno == EINTR);</span>
<span class="lineNum">      96 </span>                :            :         }
<span class="lineNum">      97 </span>                :            :     }
<span class="lineNum">      98 </span>        [<span class="branchNoCov" title="Branch 0 was not taken"> - </span><span class="branchCov" title="Branch 1 was taken 3 times"> + </span>]:<span class="lineCov">          3 :     if (rv == -1) {</span>
<span class="lineNum">      99 </span>                :<span class="lineNoCov">          0 :         (*len) = 0;</span>
<span class="lineNum">     100 </span>                :<span class="lineNoCov">          0 :         return errno;</span>
<span class="lineNum">     101 </span>                :            :     }
<span class="lineNum">     102 </span>[<span class="branchCov" title="Branch 0 was taken 1 time"> + </span><span class="branchCov" title="Branch 1 was taken 2 times"> + </span>][<span class="branchCov" title="Branch 2 was taken 1 time"> + </span><span class="branchNoCov" title="Branch 3 was not taken"> - </span>]:<span class="lineCov">          3 :     if ((sock-&gt;timeout &gt; 0) &amp;&amp; (rv &lt; *len)) {</span>
<span class="lineNum">     103 </span>                :<span class="lineCov">          1 :         sock-&gt;options |= APR_INCOMPLETE_READ;</span>
<span class="lineNum">     104 </span>                :            :     }
<span class="lineNum">     105 </span>                :<span class="lineCov">          3 :     (*len) = rv;</span>
<span class="lineNum">     106 </span>        [<span class="branchNoCov" title="Branch 0 was not taken"> - </span><span class="branchCov" title="Branch 1 was taken 3 times"> + </span>]:<span class="lineCov">          3 :     if (rv == 0) {</span>
<span class="lineNum">     107 </span>                :<span class="lineNoCov">          0 :         return APR_EOF;</span>
<span class="lineNum">     108 </span>                :            :     }
<span class="lineNum">     109 </span>                :<span class="lineCov">          4 :     return APR_SUCCESS;</span>
<span class="lineNum">     110 </span>                :            : }
<span class="lineNum">     111 </span>                :            : 
<span class="lineNum">     112 </span>                :            : apr_status_t apr_socket_sendto(apr_socket_t *sock, apr_sockaddr_t *where,
<a name="113"><span class="lineNum">     113 </span>                :            :                                apr_int32_t flags, const char *buf,</a>
<span class="lineNum">     114 </span>                :            :                                apr_size_t *len)
<span class="lineNum">     115 </span>                :<span class="lineCov">          8 : {</span>
<span class="lineNum">     116 </span>                :            :     apr_ssize_t rv;
<span class="lineNum">     117 </span>                :            : 
<span class="lineNum">     118 </span>                :            :     do {
<span class="lineNum">     119 </span>                :<span class="lineCov">          8 :         rv = sendto(sock-&gt;socketdes, buf, (*len), flags, </span>
<span class="lineNum">     120 </span>                :            :                     (const struct sockaddr*)&amp;where-&gt;sa, 
<span class="lineNum">     121 </span>                :            :                     where-&gt;salen);
<span class="lineNum">     122 </span>[<span class="branchNoCov" title="Branch 0 was not taken"> - </span><span class="branchCov" title="Branch 1 was taken 8 times"> + </span>][<span class="branchNoExec" title="Branch 3 was not executed"> # </span><span class="branchNoExec" title="Branch 4 was not executed"> # </span>]:<span class="lineCov">          8 :     } while (rv == -1 &amp;&amp; errno == EINTR);</span>
<span class="lineNum">     123 </span>                :            : 
<span class="lineNum">     124 </span>[<span class="branchNoCov" title="Branch 0 was not taken"> - </span><span class="branchCov" title="Branch 1 was taken 8 times"> + </span>][<span class="branchNoExec" title="Branch 3 was not executed"> # </span><span class="branchNoExec" title="Branch 4 was not executed"> # </span>]:<span class="lineCov">          8 :     while ((rv == -1) &amp;&amp; (errno == EAGAIN || errno == EWOULDBLOCK)</span>
<span class="lineNum">         </span>        [<span class="branchNoExec" title="Branch 5 was not executed"> # </span><span class="branchNoExec" title="Branch 6 was not executed"> # </span>]
<span class="lineNum">     125 </span>                :            :                       &amp;&amp; (sock-&gt;timeout &gt; 0)) {
<span class="lineNum">     126 </span>                :<span class="lineNoCov">          0 :         apr_status_t arv = apr_wait_for_io_or_timeout(NULL, sock, 0);</span>
<span class="lineNum">     127 </span>        [<span class="branchNoExec" title="Branch 0 was not executed"> # </span><span class="branchNoExec" title="Branch 1 was not executed"> # </span>]:<span class="lineNoCov">          0 :         if (arv != APR_SUCCESS) {</span>
<span class="lineNum">     128 </span>                :<span class="lineNoCov">          0 :             *len = 0;</span>
<span class="lineNum">     129 </span>                :<span class="lineNoCov">          0 :             return arv;</span>
<span class="lineNum">     130 </span>                :            :         } else {
<span class="lineNum">     131 </span>                :            :             do {
<span class="lineNum">     132 </span>                :<span class="lineNoCov">          0 :                 rv = sendto(sock-&gt;socketdes, buf, (*len), flags,</span>
<span class="lineNum">     133 </span>                :            :                             (const struct sockaddr*)&amp;where-&gt;sa,
<span class="lineNum">     134 </span>                :            :                             where-&gt;salen);
<span class="lineNum">     135 </span>[<span class="branchNoExec" title="Branch 0 was not executed"> # </span><span class="branchNoExec" title="Branch 1 was not executed"> # </span>][<span class="branchNoExec" title="Branch 3 was not executed"> # </span><span class="branchNoExec" title="Branch 4 was not executed"> # </span>]:<span class="lineNoCov">          0 :             } while (rv == -1 &amp;&amp; errno == EINTR);</span>
<span class="lineNum">     136 </span>                :            :         }
<span class="lineNum">     137 </span>                :            :     }
<span class="lineNum">     138 </span>        [<span class="branchNoCov" title="Branch 0 was not taken"> - </span><span class="branchCov" title="Branch 1 was taken 8 times"> + </span>]:<span class="lineCov">          8 :     if (rv == -1) {</span>
<span class="lineNum">     139 </span>                :<span class="lineNoCov">          0 :         *len = 0;</span>
<span class="lineNum">     140 </span>                :<span class="lineNoCov">          0 :         return errno;</span>
<span class="lineNum">     141 </span>                :            :     }
<span class="lineNum">     142 </span>                :<span class="lineCov">          8 :     *len = rv;</span>
<span class="lineNum">     143 </span>                :<span class="lineCov">          8 :     return APR_SUCCESS;</span>
<span class="lineNum">     144 </span>                :            : }
<span class="lineNum">     145 </span>                :            : 
<span class="lineNum">     146 </span>                :            : apr_status_t apr_socket_recvfrom(apr_sockaddr_t *from, apr_socket_t *sock,
<a name="147"><span class="lineNum">     147 </span>                :            :                                  apr_int32_t flags, char *buf, </a>
<span class="lineNum">     148 </span>                :            :                                  apr_size_t *len)
<span class="lineNum">     149 </span>                :<span class="lineCov">         10 : {</span>
<span class="lineNum">     150 </span>                :            :     apr_ssize_t rv;
<span class="lineNum">     151 </span>                :            :     
<span class="lineNum">     152 </span>                :<span class="lineCov">         10 :     from-&gt;salen = sizeof(from-&gt;sa);</span>
<span class="lineNum">     153 </span>                :            : 
<span class="lineNum">     154 </span>                :            :     do {
<span class="lineNum">     155 </span>                :<span class="lineCov">         20 :         rv = recvfrom(sock-&gt;socketdes, buf, (*len), flags, </span>
<span class="lineNum">     156 </span>                :            :                       (struct sockaddr*)&amp;from-&gt;sa, &amp;from-&gt;salen);
<span class="lineNum">     157 </span>[<span class="branchNoCov" title="Branch 0 was not taken"> - </span><span class="branchCov" title="Branch 1 was taken 10 times"> + </span>][<span class="branchNoExec" title="Branch 3 was not executed"> # </span><span class="branchNoExec" title="Branch 4 was not executed"> # </span>]:<span class="lineCov">         10 :     } while (rv == -1 &amp;&amp; errno == EINTR);</span>
<span class="lineNum">     158 </span>                :            : 
<span class="lineNum">     159 </span>[<span class="branchNoCov" title="Branch 0 was not taken"> - </span><span class="branchCov" title="Branch 1 was taken 10 times"> + </span>][<span class="branchNoExec" title="Branch 3 was not executed"> # </span><span class="branchNoExec" title="Branch 4 was not executed"> # </span>]:<span class="lineCov">         10 :     while ((rv == -1) &amp;&amp; (errno == EAGAIN || errno == EWOULDBLOCK)</span>
<span class="lineNum">         </span>        [<span class="branchNoExec" title="Branch 5 was not executed"> # </span><span class="branchNoExec" title="Branch 6 was not executed"> # </span>]
<span class="lineNum">     160 </span>                :            :                       &amp;&amp; (sock-&gt;timeout &gt; 0)) {
<span class="lineNum">     161 </span>                :<span class="lineNoCov">          0 :         apr_status_t arv = apr_wait_for_io_or_timeout(NULL, sock, 1);</span>
<span class="lineNum">     162 </span>        [<span class="branchNoExec" title="Branch 0 was not executed"> # </span><span class="branchNoExec" title="Branch 1 was not executed"> # </span>]:<span class="lineNoCov">          0 :         if (arv != APR_SUCCESS) {</span>
<span class="lineNum">     163 </span>                :<span class="lineNoCov">          0 :             *len = 0;</span>
<span class="lineNum">     164 </span>                :<span class="lineNoCov">          0 :             return arv;</span>
<span class="lineNum">     165 </span>                :            :         } else {
<span class="lineNum">     166 </span>                :            :             do {
<span class="lineNum">     167 </span>                :<span class="lineNoCov">          0 :                 rv = recvfrom(sock-&gt;socketdes, buf, (*len), flags,</span>
<span class="lineNum">     168 </span>                :            :                               (struct sockaddr*)&amp;from-&gt;sa, &amp;from-&gt;salen);
<span class="lineNum">     169 </span>[<span class="branchNoExec" title="Branch 0 was not executed"> # </span><span class="branchNoExec" title="Branch 1 was not executed"> # </span>][<span class="branchNoExec" title="Branch 3 was not executed"> # </span><span class="branchNoExec" title="Branch 4 was not executed"> # </span>]:<span class="lineNoCov">          0 :             } while (rv == -1 &amp;&amp; errno == EINTR);</span>
<span class="lineNum">     170 </span>                :            :         }
<span class="lineNum">     171 </span>                :            :     }
<span class="lineNum">     172 </span>        [<span class="branchNoCov" title="Branch 0 was not taken"> - </span><span class="branchCov" title="Branch 1 was taken 10 times"> + </span>]:<span class="lineCov">         10 :     if (rv == -1) {</span>
<span class="lineNum">     173 </span>                :<span class="lineNoCov">          0 :         (*len) = 0;</span>
<span class="lineNum">     174 </span>                :<span class="lineNoCov">          0 :         return errno;</span>
<span class="lineNum">     175 </span>                :            :     }
<span class="lineNum">     176 </span>                :            : 
<span class="lineNum">     177 </span>        [<span class="branchNoCov" title="Branch 1 was not taken"> - </span><span class="branchCov" title="Branch 2 was taken 10 times"> + </span>]:<span class="lineCov">         10 :     apr_sockaddr_vars_set(from, from-&gt;sa.sin.sin_family, ntohs(from-&gt;sa.sin.sin_port));</span>
<span class="lineNum">     178 </span>                :            : 
<span class="lineNum">     179 </span>                :<span class="lineCov">         10 :     (*len) = rv;</span>
<span class="lineNum">     180 </span>[<span class="branchCov" title="Branch 0 was taken 2 times"> + </span><span class="branchCov" title="Branch 1 was taken 8 times"> + </span>][<span class="branchCov" title="Branch 2 was taken 2 times"> + </span><span class="branchNoCov" title="Branch 3 was not taken"> - </span>]:<span class="lineCov">         10 :     if (rv == 0 &amp;&amp; sock-&gt;type == SOCK_STREAM) {</span>
<span class="lineNum">     181 </span>                :<span class="lineCov">          2 :         return APR_EOF;</span>
<span class="lineNum">     182 </span>                :            :     }
<span class="lineNum">     183 </span>                :            : 
<span class="lineNum">     184 </span>                :<span class="lineCov">         10 :     return APR_SUCCESS;</span>
<span class="lineNum">     185 </span>                :            : }
<span class="lineNum">     186 </span>                :            : 
<a name="187"><span class="lineNum">     187 </span>                :            : apr_status_t apr_socket_sendv(apr_socket_t * sock, const struct iovec *vec,</a>
<span class="lineNum">     188 </span>                :            :                               apr_int32_t nvec, apr_size_t *len)
<span class="lineNum">     189 </span>                :<span class="lineNoCov">          0 : {</span>
<span class="lineNum">     190 </span>                :            : #ifdef HAVE_WRITEV
<span class="lineNum">     191 </span>                :            :     apr_ssize_t rv;
<span class="lineNum">     192 </span>                :<span class="lineNoCov">          0 :     apr_size_t requested_len = 0;</span>
<span class="lineNum">     193 </span>                :            :     apr_int32_t i;
<span class="lineNum">     194 </span>                :            : 
<span class="lineNum">     195 </span>        [<span class="branchNoExec" title="Branch 0 was not executed"> # </span><span class="branchNoExec" title="Branch 1 was not executed"> # </span>]:<span class="lineNoCov">          0 :     for (i = 0; i &lt; nvec; i++) {</span>
<span class="lineNum">     196 </span>                :<span class="lineNoCov">          0 :         requested_len += vec[i].iov_len;</span>
<span class="lineNum">     197 </span>                :            :     }
<span class="lineNum">     198 </span>                :            : 
<span class="lineNum">     199 </span>        [<span class="branchNoExec" title="Branch 0 was not executed"> # </span><span class="branchNoExec" title="Branch 1 was not executed"> # </span>]:<span class="lineNoCov">          0 :     if (sock-&gt;options &amp; APR_INCOMPLETE_WRITE) {</span>
<span class="lineNum">     200 </span>                :<span class="lineNoCov">          0 :         sock-&gt;options &amp;= ~APR_INCOMPLETE_WRITE;</span>
<span class="lineNum">     201 </span>                :<span class="lineNoCov">          0 :         goto do_select;</span>
<span class="lineNum">     202 </span>                :            :     }
<span class="lineNum">     203 </span>                :            : 
<span class="lineNum">     204 </span>                :            :     do {
<span class="lineNum">     205 </span>                :<span class="lineNoCov">          0 :         rv = writev(sock-&gt;socketdes, vec, nvec);</span>
<span class="lineNum">     206 </span>[<span class="branchNoExec" title="Branch 0 was not executed"> # </span><span class="branchNoExec" title="Branch 1 was not executed"> # </span>][<span class="branchNoExec" title="Branch 3 was not executed"> # </span><span class="branchNoExec" title="Branch 4 was not executed"> # </span>]:<span class="lineNoCov">          0 :     } while (rv == -1 &amp;&amp; errno == EINTR);</span>
<span class="lineNum">     207 </span>                :            : 
<span class="lineNum">     208 </span>[<span class="branchNoExec" title="Branch 0 was not executed"> # </span><span class="branchNoExec" title="Branch 1 was not executed"> # </span>][<span class="branchNoExec" title="Branch 3 was not executed"> # </span><span class="branchNoExec" title="Branch 4 was not executed"> # </span>]:<span class="lineNoCov">          0 :     while ((rv == -1) &amp;&amp; (errno == EAGAIN || errno == EWOULDBLOCK) </span>
<span class="lineNum">         </span>        [<span class="branchNoExec" title="Branch 5 was not executed"> # </span><span class="branchNoExec" title="Branch 6 was not executed"> # </span>]
<span class="lineNum">     209 </span>                :            :                       &amp;&amp; (sock-&gt;timeout &gt; 0)) {
<span class="lineNum">     210 </span>                :            :         apr_status_t arv;
<span class="lineNum">     211 </span>                :<span class="lineNoCov">          0 : do_select:</span>
<span class="lineNum">     212 </span>                :<span class="lineNoCov">          0 :         arv = apr_wait_for_io_or_timeout(NULL, sock, 0);</span>
<span class="lineNum">     213 </span>        [<span class="branchNoExec" title="Branch 0 was not executed"> # </span><span class="branchNoExec" title="Branch 1 was not executed"> # </span>]:<span class="lineNoCov">          0 :         if (arv != APR_SUCCESS) {</span>
<span class="lineNum">     214 </span>                :<span class="lineNoCov">          0 :             *len = 0;</span>
<span class="lineNum">     215 </span>                :<span class="lineNoCov">          0 :             return arv;</span>
<span class="lineNum">     216 </span>                :            :         }
<span class="lineNum">     217 </span>                :            :         else {
<span class="lineNum">     218 </span>                :            :             do {
<span class="lineNum">     219 </span>                :<span class="lineNoCov">          0 :                 rv = writev(sock-&gt;socketdes, vec, nvec);</span>
<span class="lineNum">     220 </span>[<span class="branchNoExec" title="Branch 0 was not executed"> # </span><span class="branchNoExec" title="Branch 1 was not executed"> # </span>][<span class="branchNoExec" title="Branch 3 was not executed"> # </span><span class="branchNoExec" title="Branch 4 was not executed"> # </span>]:<span class="lineNoCov">          0 :             } while (rv == -1 &amp;&amp; errno == EINTR);</span>
<span class="lineNum">     221 </span>                :            :         }
<span class="lineNum">     222 </span>                :            :     }
<span class="lineNum">     223 </span>        [<span class="branchNoExec" title="Branch 0 was not executed"> # </span><span class="branchNoExec" title="Branch 1 was not executed"> # </span>]:<span class="lineNoCov">          0 :     if (rv == -1) {</span>
<span class="lineNum">     224 </span>                :<span class="lineNoCov">          0 :         *len = 0;</span>
<span class="lineNum">     225 </span>                :<span class="lineNoCov">          0 :         return errno;</span>
<span class="lineNum">     226 </span>                :            :     }
<span class="lineNum">     227 </span>        [<span class="branchNoExec" title="Branch 0 was not executed"> # </span><span class="branchNoExec" title="Branch 1 was not executed"> # </span>]:<span class="lineNoCov">          0 :     if ((sock-&gt;timeout &gt; 0) &amp;&amp; (rv &lt; requested_len)) {</span>
<span class="lineNum">     228 </span>                :<span class="lineNoCov">          0 :         sock-&gt;options |= APR_INCOMPLETE_WRITE;</span>
<span class="lineNum">     229 </span>                :            :     }
<span class="lineNum">     230 </span>                :<span class="lineNoCov">          0 :     (*len) = rv;</span>
<span class="lineNum">     231 </span>                :<span class="lineNoCov">          0 :     return APR_SUCCESS;</span>
<span class="lineNum">     232 </span>                :            : #else
<span class="lineNum">     233 </span>                :            :     *len = vec[0].iov_len;
<span class="lineNum">     234 </span>                :            :     return apr_socket_send(sock, vec[0].iov_base, len);
<span class="lineNum">     235 </span>                :            : #endif
<span class="lineNum">     236 </span>                :            : }
<span class="lineNum">     237 </span>                :            : 
<span class="lineNum">     238 </span>                :            : #if APR_HAS_SENDFILE
<span class="lineNum">     239 </span>                :            : 
<span class="lineNum">     240 </span>                :            : /* TODO: Verify that all platforms handle the fd the same way,
<span class="lineNum">     241 </span>                :            :  * i.e. that they don't move the file pointer.
<span class="lineNum">     242 </span>                :            :  */
<span class="lineNum">     243 </span>                :            : /* TODO: what should flags be?  int_32? */
<span class="lineNum">     244 </span>                :            : 
<span class="lineNum">     245 </span>                :            : /* Define a structure to pass in when we have a NULL header value */
<span class="lineNum">     246 </span>                :            : static apr_hdtr_t no_hdtr;
<span class="lineNum">     247 </span>                :            : 
<span class="lineNum">     248 </span>                :            : #if defined(__linux__) &amp;&amp; defined(HAVE_WRITEV)
<span class="lineNum">     249 </span>                :            : 
<span class="lineNum">     250 </span>                :            : apr_status_t apr_socket_sendfile(apr_socket_t *sock, apr_file_t *file,
<a name="251"><span class="lineNum">     251 </span>                :            :                                  apr_hdtr_t *hdtr, apr_off_t *offset,</a>
<span class="lineNum">     252 </span>                :            :                                  apr_size_t *len, apr_int32_t flags)
<span class="lineNum">     253 </span>                :<span class="lineNoCov">          0 : {</span>
<span class="lineNum">     254 </span>                :<span class="lineNoCov">          0 :     int rv, nbytes = 0, total_hdrbytes, i;</span>
<span class="lineNum">     255 </span>                :            :     apr_status_t arv;
<span class="lineNum">     256 </span>                :            : 
<span class="lineNum">     257 </span>                :            : #if APR_HAS_LARGE_FILES &amp;&amp; defined(HAVE_SENDFILE64)
<span class="lineNum">     258 </span>                :<span class="lineNoCov">          0 :     apr_off_t off = *offset;</span>
<span class="lineNum">     259 </span>                :            : #define sendfile sendfile64
<span class="lineNum">     260 </span>                :            : 
<span class="lineNum">     261 </span>                :            : #elif APR_HAS_LARGE_FILES &amp;&amp; SIZEOF_OFF_T == 4
<span class="lineNum">     262 </span>                :            :     /* 64-bit apr_off_t but no sendfile64(): fail if trying to send
<span class="lineNum">     263 </span>                :            :      * past the 2Gb limit. */
<span class="lineNum">     264 </span>                :            :     off_t off;
<span class="lineNum">     265 </span>                :            :     
<span class="lineNum">     266 </span>                :            :     if ((apr_int64_t)*offset + *len &gt; INT_MAX) {
<span class="lineNum">     267 </span>                :            :         return EINVAL;
<span class="lineNum">     268 </span>                :            :     }
<span class="lineNum">     269 </span>                :            :     
<span class="lineNum">     270 </span>                :            :     off = *offset;
<span class="lineNum">     271 </span>                :            : 
<span class="lineNum">     272 </span>                :            : #else
<span class="lineNum">     273 </span>                :            :     off_t off = *offset;
<span class="lineNum">     274 </span>                :            : 
<span class="lineNum">     275 </span>                :            :     /* Multiple reports have shown sendfile failing with EINVAL if
<span class="lineNum">     276 </span>                :            :      * passed a &gt;=2Gb count value on some 64-bit kernels.  It won't
<span class="lineNum">     277 </span>                :            :      * noticably hurt performance to limit each call to &lt;2Gb at a
<span class="lineNum">     278 </span>                :            :      * time, so avoid that issue here: */
<span class="lineNum">     279 </span>                :            :     if (sizeof(off_t) == 8 &amp;&amp; *len &gt; INT_MAX) {
<span class="lineNum">     280 </span>                :            :         *len = INT_MAX;
<span class="lineNum">     281 </span>                :            :     }
<span class="lineNum">     282 </span>                :            : #endif
<span class="lineNum">     283 </span>                :            : 
<span class="lineNum">     284 </span>        [<span class="branchNoExec" title="Branch 0 was not executed"> # </span><span class="branchNoExec" title="Branch 1 was not executed"> # </span>]:<span class="lineNoCov">          0 :     if (!hdtr) {</span>
<span class="lineNum">     285 </span>                :<span class="lineNoCov">          0 :         hdtr = &amp;no_hdtr;</span>
<span class="lineNum">     286 </span>                :            :     }
<span class="lineNum">     287 </span>                :            : 
<span class="lineNum">     288 </span>                :            :     /* Ignore flags for now. */
<span class="lineNum">     289 </span>                :<span class="lineNoCov">          0 :     flags = 0;</span>
<span class="lineNum">     290 </span>                :            : 
<span class="lineNum">     291 </span>        [<span class="branchNoExec" title="Branch 0 was not executed"> # </span><span class="branchNoExec" title="Branch 1 was not executed"> # </span>]:<span class="lineNoCov">          0 :     if (hdtr-&gt;numheaders &gt; 0) {</span>
<span class="lineNum">     292 </span>                :            :         apr_size_t hdrbytes;
<span class="lineNum">     293 </span>                :            : 
<span class="lineNum">     294 </span>                :            :         /* cork before writing headers */
<span class="lineNum">     295 </span>                :<span class="lineNoCov">          0 :         rv = apr_socket_opt_set(sock, APR_TCP_NOPUSH, 1);</span>
<span class="lineNum">     296 </span>        [<span class="branchNoExec" title="Branch 0 was not executed"> # </span><span class="branchNoExec" title="Branch 1 was not executed"> # </span>]:<span class="lineNoCov">          0 :         if (rv != APR_SUCCESS) {</span>
<span class="lineNum">     297 </span>                :<span class="lineNoCov">          0 :             return rv;</span>
<span class="lineNum">     298 </span>                :            :         }
<span class="lineNum">     299 </span>                :            : 
<span class="lineNum">     300 </span>                :            :         /* Now write the headers */
<span class="lineNum">     301 </span>                :<span class="lineNoCov">          0 :         arv = apr_socket_sendv(sock, hdtr-&gt;headers, hdtr-&gt;numheaders,</span>
<span class="lineNum">     302 </span>                :            :                                &amp;hdrbytes);
<span class="lineNum">     303 </span>        [<span class="branchNoExec" title="Branch 0 was not executed"> # </span><span class="branchNoExec" title="Branch 1 was not executed"> # </span>]:<span class="lineNoCov">          0 :         if (arv != APR_SUCCESS) {</span>
<span class="lineNum">     304 </span>                :<span class="lineNoCov">          0 :             *len = 0;</span>
<span class="lineNum">     305 </span>                :<span class="lineNoCov">          0 :             return errno;</span>
<span class="lineNum">     306 </span>                :            :         }
<span class="lineNum">     307 </span>                :<span class="lineNoCov">          0 :         nbytes += hdrbytes;</span>
<span class="lineNum">     308 </span>                :            : 
<span class="lineNum">     309 </span>                :            :         /* If this was a partial write and we aren't doing timeouts, 
<span class="lineNum">     310 </span>                :            :          * return now with the partial byte count; this is a non-blocking 
<span class="lineNum">     311 </span>                :            :          * socket.
<span class="lineNum">     312 </span>                :            :          */
<span class="lineNum">     313 </span>                :<span class="lineNoCov">          0 :         total_hdrbytes = 0;</span>
<span class="lineNum">     314 </span>        [<span class="branchNoExec" title="Branch 0 was not executed"> # </span><span class="branchNoExec" title="Branch 1 was not executed"> # </span>]:<span class="lineNoCov">          0 :         for (i = 0; i &lt; hdtr-&gt;numheaders; i++) {</span>
<span class="lineNum">     315 </span>                :<span class="lineNoCov">          0 :             total_hdrbytes += hdtr-&gt;headers[i].iov_len;</span>
<span class="lineNum">     316 </span>                :            :         }
<span class="lineNum">     317 </span>        [<span class="branchNoExec" title="Branch 0 was not executed"> # </span><span class="branchNoExec" title="Branch 1 was not executed"> # </span>]:<span class="lineNoCov">          0 :         if (hdrbytes &lt; total_hdrbytes) {</span>
<span class="lineNum">     318 </span>                :<span class="lineNoCov">          0 :             *len = hdrbytes;</span>
<span class="lineNum">     319 </span>                :<span class="lineNoCov">          0 :             return apr_socket_opt_set(sock, APR_TCP_NOPUSH, 0);</span>
<span class="lineNum">     320 </span>                :            :         }
<span class="lineNum">     321 </span>                :            :     }
<span class="lineNum">     322 </span>                :            : 
<span class="lineNum">     323 </span>        [<span class="branchNoExec" title="Branch 0 was not executed"> # </span><span class="branchNoExec" title="Branch 1 was not executed"> # </span>]:<span class="lineNoCov">          0 :     if (sock-&gt;options &amp; APR_INCOMPLETE_WRITE) {</span>
<span class="lineNum">     324 </span>                :<span class="lineNoCov">          0 :         sock-&gt;options &amp;= ~APR_INCOMPLETE_WRITE;</span>
<span class="lineNum">     325 </span>                :<span class="lineNoCov">          0 :         goto do_select;</span>
<span class="lineNum">     326 </span>                :            :     }
<span class="lineNum">     327 </span>                :            : 
<span class="lineNum">     328 </span>                :            :     do {
<span class="lineNum">     329 </span>                :<span class="lineNoCov">          0 :         rv = sendfile(sock-&gt;socketdes,    /* socket */</span>
<span class="lineNum">     330 </span>                :            :                       file-&gt;filedes, /* open file descriptor of the file to be sent */
<span class="lineNum">     331 </span>                :            :                       &amp;off,    /* where in the file to start */
<span class="lineNum">     332 </span>                :            :                       *len);   /* number of bytes to send */
<span class="lineNum">     333 </span>[<span class="branchNoExec" title="Branch 0 was not executed"> # </span><span class="branchNoExec" title="Branch 1 was not executed"> # </span>][<span class="branchNoExec" title="Branch 3 was not executed"> # </span><span class="branchNoExec" title="Branch 4 was not executed"> # </span>]:<span class="lineNoCov">          0 :     } while (rv == -1 &amp;&amp; errno == EINTR);</span>
<span class="lineNum">     334 </span>                :            : 
<span class="lineNum">     335 </span>[<span class="branchNoExec" title="Branch 0 was not executed"> # </span><span class="branchNoExec" title="Branch 1 was not executed"> # </span>][<span class="branchNoExec" title="Branch 3 was not executed"> # </span><span class="branchNoExec" title="Branch 4 was not executed"> # </span>]:<span class="lineNoCov">          0 :     while ((rv == -1) &amp;&amp; (errno == EAGAIN || errno == EWOULDBLOCK) </span>
<span class="lineNum">         </span>        [<span class="branchNoExec" title="Branch 5 was not executed"> # </span><span class="branchNoExec" title="Branch 6 was not executed"> # </span>]
<span class="lineNum">     336 </span>                :            :                       &amp;&amp; (sock-&gt;timeout &gt; 0)) {
<span class="lineNum">     337 </span>                :<span class="lineNoCov">          0 : do_select:</span>
<span class="lineNum">     338 </span>                :<span class="lineNoCov">          0 :         arv = apr_wait_for_io_or_timeout(NULL, sock, 0);</span>
<span class="lineNum">     339 </span>        [<span class="branchNoExec" title="Branch 0 was not executed"> # </span><span class="branchNoExec" title="Branch 1 was not executed"> # </span>]:<span class="lineNoCov">          0 :         if (arv != APR_SUCCESS) {</span>
<span class="lineNum">     340 </span>                :<span class="lineNoCov">          0 :             *len = 0;</span>
<span class="lineNum">     341 </span>                :<span class="lineNoCov">          0 :             return arv;</span>
<span class="lineNum">     342 </span>                :            :         }
<span class="lineNum">     343 </span>                :            :         else {
<span class="lineNum">     344 </span>                :            :             do {
<span class="lineNum">     345 </span>                :<span class="lineNoCov">          0 :                 rv = sendfile(sock-&gt;socketdes,    /* socket */</span>
<span class="lineNum">     346 </span>                :            :                               file-&gt;filedes, /* open file descriptor of the file to be sent */
<span class="lineNum">     347 </span>                :            :                               &amp;off,    /* where in the file to start */
<span class="lineNum">     348 </span>                :            :                               *len);    /* number of bytes to send */
<span class="lineNum">     349 </span>[<span class="branchNoExec" title="Branch 0 was not executed"> # </span><span class="branchNoExec" title="Branch 1 was not executed"> # </span>][<span class="branchNoExec" title="Branch 3 was not executed"> # </span><span class="branchNoExec" title="Branch 4 was not executed"> # </span>]:<span class="lineNoCov">          0 :             } while (rv == -1 &amp;&amp; errno == EINTR);</span>
<span class="lineNum">     350 </span>                :            :         }
<span class="lineNum">     351 </span>                :            :     }
<span class="lineNum">     352 </span>                :            : 
<span class="lineNum">     353 </span>        [<span class="branchNoExec" title="Branch 0 was not executed"> # </span><span class="branchNoExec" title="Branch 1 was not executed"> # </span>]:<span class="lineNoCov">          0 :     if (rv == -1) {</span>
<span class="lineNum">     354 </span>                :<span class="lineNoCov">          0 :         *len = nbytes;</span>
<span class="lineNum">     355 </span>                :<span class="lineNoCov">          0 :         rv = errno;</span>
<span class="lineNum">     356 </span>                :<span class="lineNoCov">          0 :         apr_socket_opt_set(sock, APR_TCP_NOPUSH, 0);</span>
<span class="lineNum">     357 </span>                :<span class="lineNoCov">          0 :         return rv;</span>
<span class="lineNum">     358 </span>                :            :     }
<span class="lineNum">     359 </span>                :            : 
<span class="lineNum">     360 </span>                :<span class="lineNoCov">          0 :     nbytes += rv;</span>
<span class="lineNum">     361 </span>                :            : 
<span class="lineNum">     362 </span>        [<span class="branchNoExec" title="Branch 0 was not executed"> # </span><span class="branchNoExec" title="Branch 1 was not executed"> # </span>]:<span class="lineNoCov">          0 :     if (rv &lt; *len) {</span>
<span class="lineNum">     363 </span>                :<span class="lineNoCov">          0 :         *len = nbytes;</span>
<span class="lineNum">     364 </span>                :<span class="lineNoCov">          0 :         arv = apr_socket_opt_set(sock, APR_TCP_NOPUSH, 0);</span>
<span class="lineNum">     365 </span>        [<span class="branchNoExec" title="Branch 0 was not executed"> # </span><span class="branchNoExec" title="Branch 1 was not executed"> # </span>]:<span class="lineNoCov">          0 :         if (rv &gt; 0) {</span>
<span class="lineNum">     366 </span>                :            :                 
<span class="lineNum">     367 </span>                :            :             /* If this was a partial write, return now with the 
<span class="lineNum">     368 </span>                :            :              * partial byte count;  this is a non-blocking socket.
<span class="lineNum">     369 </span>                :            :              */
<span class="lineNum">     370 </span>                :            : 
<span class="lineNum">     371 </span>        [<span class="branchNoExec" title="Branch 0 was not executed"> # </span><span class="branchNoExec" title="Branch 1 was not executed"> # </span>]:<span class="lineNoCov">          0 :             if (sock-&gt;timeout &gt; 0) {</span>
<span class="lineNum">     372 </span>                :<span class="lineNoCov">          0 :                 sock-&gt;options |= APR_INCOMPLETE_WRITE;</span>
<span class="lineNum">     373 </span>                :            :             }
<span class="lineNum">     374 </span>                :<span class="lineNoCov">          0 :             return arv;</span>
<span class="lineNum">     375 </span>                :            :         }
<span class="lineNum">     376 </span>                :            :         else {
<span class="lineNum">     377 </span>                :            :             /* If the file got smaller mid-request, eventually the offset
<span class="lineNum">     378 </span>                :            :              * becomes equal to the new file size and the kernel returns 0.  
<span class="lineNum">     379 </span>                :            :              * Make this an error so the caller knows to log something and
<span class="lineNum">     380 </span>                :            :              * exit.
<span class="lineNum">     381 </span>                :            :              */
<span class="lineNum">     382 </span>                :<span class="lineNoCov">          0 :             return APR_EOF;</span>
<span class="lineNum">     383 </span>                :            :         }
<span class="lineNum">     384 </span>                :            :     }
<span class="lineNum">     385 </span>                :            : 
<span class="lineNum">     386 </span>                :            :     /* Now write the footers */
<span class="lineNum">     387 </span>        [<span class="branchNoExec" title="Branch 0 was not executed"> # </span><span class="branchNoExec" title="Branch 1 was not executed"> # </span>]:<span class="lineNoCov">          0 :     if (hdtr-&gt;numtrailers &gt; 0) {</span>
<span class="lineNum">     388 </span>                :            :         apr_size_t trbytes;
<span class="lineNum">     389 </span>                :<span class="lineNoCov">          0 :         arv = apr_socket_sendv(sock, hdtr-&gt;trailers, hdtr-&gt;numtrailers, </span>
<span class="lineNum">     390 </span>                :            :                                &amp;trbytes);
<span class="lineNum">     391 </span>                :<span class="lineNoCov">          0 :         nbytes += trbytes;</span>
<span class="lineNum">     392 </span>        [<span class="branchNoExec" title="Branch 0 was not executed"> # </span><span class="branchNoExec" title="Branch 1 was not executed"> # </span>]:<span class="lineNoCov">          0 :         if (arv != APR_SUCCESS) {</span>
<span class="lineNum">     393 </span>                :<span class="lineNoCov">          0 :             *len = nbytes;</span>
<span class="lineNum">     394 </span>                :<span class="lineNoCov">          0 :             rv = errno;</span>
<span class="lineNum">     395 </span>                :<span class="lineNoCov">          0 :             apr_socket_opt_set(sock, APR_TCP_NOPUSH, 0);</span>
<span class="lineNum">     396 </span>                :<span class="lineNoCov">          0 :             return rv;</span>
<span class="lineNum">     397 </span>                :            :         }
<span class="lineNum">     398 </span>                :            :     }
<span class="lineNum">     399 </span>                :            : 
<span class="lineNum">     400 </span>                :<span class="lineNoCov">          0 :     apr_socket_opt_set(sock, APR_TCP_NOPUSH, 0);</span>
<span class="lineNum">     401 </span>                :            :     
<span class="lineNum">     402 </span>                :<span class="lineNoCov">          0 :     (*len) = nbytes;</span>
<span class="lineNum">     403 </span>        [<span class="branchNoExec" title="Branch 0 was not executed"> # </span><span class="branchNoExec" title="Branch 1 was not executed"> # </span>]:<span class="lineNoCov">          0 :     return rv &lt; 0 ? errno : APR_SUCCESS;</span>
<span class="lineNum">     404 </span>                :            : }
<span class="lineNum">     405 </span>                :            : 
<span class="lineNum">     406 </span>                :            : #elif defined(DARWIN)
<span class="lineNum">     407 </span>                :            : 
<span class="lineNum">     408 </span>                :            : /* OS/X Release 10.5 or greater */
<span class="lineNum">     409 </span>                :            : apr_status_t apr_socket_sendfile(apr_socket_t *sock, apr_file_t *file,
<span class="lineNum">     410 </span>                :            :                                  apr_hdtr_t *hdtr, apr_off_t *offset,
<span class="lineNum">     411 </span>                :            :                                  apr_size_t *len, apr_int32_t flags)
<span class="lineNum">     412 </span>                :            : {
<span class="lineNum">     413 </span>                :            :     apr_off_t nbytes = 0;
<span class="lineNum">     414 </span>                :            :     apr_off_t bytes_to_send = *len;
<span class="lineNum">     415 </span>                :            :     apr_off_t bytes_sent = 0;
<span class="lineNum">     416 </span>                :            :     apr_status_t arv;
<span class="lineNum">     417 </span>                :            :     int rv = 0;
<span class="lineNum">     418 </span>                :            : 
<span class="lineNum">     419 </span>                :            :     /* Ignore flags for now. */
<span class="lineNum">     420 </span>                :            :     flags = 0;
<span class="lineNum">     421 </span>                :            : 
<span class="lineNum">     422 </span>                :            :     if (!hdtr) {
<span class="lineNum">     423 </span>                :            :         hdtr = &amp;no_hdtr;
<span class="lineNum">     424 </span>                :            :     }
<span class="lineNum">     425 </span>                :            : 
<span class="lineNum">     426 </span>                :            :     /* OS X can send the headers/footers as part of the system call, 
<span class="lineNum">     427 </span>                :            :      * but how it counts bytes isn't documented properly. We use 
<span class="lineNum">     428 </span>                :            :      * apr_socket_sendv() instead.
<span class="lineNum">     429 </span>                :            :      */
<span class="lineNum">     430 </span>                :            :      if (hdtr-&gt;numheaders &gt; 0) {
<span class="lineNum">     431 </span>                :            :         apr_size_t hbytes;
<span class="lineNum">     432 </span>                :            :         int i;
<span class="lineNum">     433 </span>                :            : 
<span class="lineNum">     434 </span>                :            :         /* Now write the headers */
<span class="lineNum">     435 </span>                :            :         arv = apr_socket_sendv(sock, hdtr-&gt;headers, hdtr-&gt;numheaders,
<span class="lineNum">     436 </span>                :            :                                &amp;hbytes);
<span class="lineNum">     437 </span>                :            :         if (arv != APR_SUCCESS) {
<span class="lineNum">     438 </span>                :            :             *len = 0;
<span class="lineNum">     439 </span>                :            :             return errno;
<span class="lineNum">     440 </span>                :            :         }
<span class="lineNum">     441 </span>                :            :         bytes_sent = hbytes;
<span class="lineNum">     442 </span>                :            : 
<span class="lineNum">     443 </span>                :            :         hbytes = 0;
<span class="lineNum">     444 </span>                :            :         for (i = 0; i &lt; hdtr-&gt;numheaders; i++) {
<span class="lineNum">     445 </span>                :            :             hbytes += hdtr-&gt;headers[i].iov_len;
<span class="lineNum">     446 </span>                :            :         }
<span class="lineNum">     447 </span>                :            :         if (bytes_sent &lt; hbytes) {
<span class="lineNum">     448 </span>                :            :             *len = bytes_sent;
<span class="lineNum">     449 </span>                :            :             return APR_SUCCESS;
<span class="lineNum">     450 </span>                :            :         }
<span class="lineNum">     451 </span>                :            :     }
<span class="lineNum">     452 </span>                :            : 
<span class="lineNum">     453 </span>                :            :     do {
<span class="lineNum">     454 </span>                :            :         if (!bytes_to_send) {
<span class="lineNum">     455 </span>                :            :             break;
<span class="lineNum">     456 </span>                :            :         }
<span class="lineNum">     457 </span>                :            :         if (sock-&gt;options &amp; APR_INCOMPLETE_WRITE) {
<span class="lineNum">     458 </span>                :            :             apr_status_t arv;
<span class="lineNum">     459 </span>                :            :             sock-&gt;options &amp;= ~APR_INCOMPLETE_WRITE;
<span class="lineNum">     460 </span>                :            :             arv = apr_wait_for_io_or_timeout(NULL, sock, 0);
<span class="lineNum">     461 </span>                :            :             if (arv != APR_SUCCESS) {
<span class="lineNum">     462 </span>                :            :                 *len = 0;
<span class="lineNum">     463 </span>                :            :                 return arv;
<span class="lineNum">     464 </span>                :            :             }
<span class="lineNum">     465 </span>                :            :         }
<span class="lineNum">     466 </span>                :            : 
<span class="lineNum">     467 </span>                :            :         nbytes = bytes_to_send;
<span class="lineNum">     468 </span>                :            :         rv = sendfile(file-&gt;filedes, /* file to be sent */
<span class="lineNum">     469 </span>                :            :                       sock-&gt;socketdes, /* socket */
<span class="lineNum">     470 </span>                :            :                       *offset,       /* where in the file to start */
<span class="lineNum">     471 </span>                :            :                       &amp;nbytes,       /* number of bytes to write/written */
<span class="lineNum">     472 </span>                :            :                       NULL,          /* Headers/footers */
<span class="lineNum">     473 </span>                :            :                       flags);        /* undefined, set to 0 */
<span class="lineNum">     474 </span>                :            : 
<span class="lineNum">     475 </span>                :            :         if (rv == -1) {
<span class="lineNum">     476 </span>                :            :             if (errno == EAGAIN) {
<span class="lineNum">     477 </span>                :            :                 if (sock-&gt;timeout &gt; 0) {
<span class="lineNum">     478 </span>                :            :                     sock-&gt;options |= APR_INCOMPLETE_WRITE;
<span class="lineNum">     479 </span>                :            :                 }
<span class="lineNum">     480 </span>                :            :                 /* BSD's sendfile can return -1/EAGAIN even if it
<span class="lineNum">     481 </span>                :            :                  * sent bytes.  Sanitize the result so we get normal EAGAIN
<span class="lineNum">     482 </span>                :            :                  * semantics w.r.t. bytes sent.
<span class="lineNum">     483 </span>                :            :                  */
<span class="lineNum">     484 </span>                :            :                 if (nbytes) {
<span class="lineNum">     485 </span>                :            :                     bytes_sent += nbytes;
<span class="lineNum">     486 </span>                :            :                     /* normal exit for a big file &amp; non-blocking io */
<span class="lineNum">     487 </span>                :            :                     (*len) = bytes_sent;
<span class="lineNum">     488 </span>                :            :                     return APR_SUCCESS;
<span class="lineNum">     489 </span>                :            :                 }
<span class="lineNum">     490 </span>                :            :             }
<span class="lineNum">     491 </span>                :            :         }
<span class="lineNum">     492 </span>                :            :         else {       /* rv == 0 (or the kernel is broken) */
<span class="lineNum">     493 </span>                :            :             bytes_sent += nbytes;
<span class="lineNum">     494 </span>                :            :             if (nbytes == 0) {
<span class="lineNum">     495 </span>                :            :                 /* Most likely the file got smaller after the stat.
<span class="lineNum">     496 </span>                :            :                  * Return an error so the caller can do the Right Thing.
<span class="lineNum">     497 </span>                :            :                  */
<span class="lineNum">     498 </span>                :            :                 (*len) = bytes_sent;
<span class="lineNum">     499 </span>                :            :                 return APR_EOF;
<span class="lineNum">     500 </span>                :            :             }
<span class="lineNum">     501 </span>                :            :         }
<span class="lineNum">     502 </span>                :            :     } while (rv == -1 &amp;&amp; (errno == EINTR || errno == EAGAIN));
<span class="lineNum">     503 </span>                :            : 
<span class="lineNum">     504 </span>                :            :     /* Now write the footers */
<span class="lineNum">     505 </span>                :            :     if (hdtr-&gt;numtrailers &gt; 0) {
<span class="lineNum">     506 </span>                :            :         apr_size_t tbytes;
<span class="lineNum">     507 </span>                :            :         arv = apr_socket_sendv(sock, hdtr-&gt;trailers, hdtr-&gt;numtrailers, 
<span class="lineNum">     508 </span>                :            :                                &amp;tbytes);
<span class="lineNum">     509 </span>                :            :         bytes_sent += tbytes;
<span class="lineNum">     510 </span>                :            :         if (arv != APR_SUCCESS) {
<span class="lineNum">     511 </span>                :            :             *len = bytes_sent;
<span class="lineNum">     512 </span>                :            :             rv = errno;
<span class="lineNum">     513 </span>                :            :             return rv;
<span class="lineNum">     514 </span>                :            :         }
<span class="lineNum">     515 </span>                :            :     }
<span class="lineNum">     516 </span>                :            : 
<span class="lineNum">     517 </span>                :            :     (*len) = bytes_sent;
<span class="lineNum">     518 </span>                :            :     if (rv == -1) {
<span class="lineNum">     519 </span>                :            :         return errno;
<span class="lineNum">     520 </span>                :            :     }
<span class="lineNum">     521 </span>                :            :     return APR_SUCCESS;
<span class="lineNum">     522 </span>                :            : }
<span class="lineNum">     523 </span>                :            : 
<span class="lineNum">     524 </span>                :            : #elif defined(__FreeBSD__) || defined(__DragonFly__)
<span class="lineNum">     525 </span>                :            : 
<span class="lineNum">     526 </span>                :            : /* Release 3.1 or greater */
<span class="lineNum">     527 </span>                :            : apr_status_t apr_socket_sendfile(apr_socket_t * sock, apr_file_t * file,
<span class="lineNum">     528 </span>                :            :                                  apr_hdtr_t * hdtr, apr_off_t * offset,
<span class="lineNum">     529 </span>                :            :                                  apr_size_t * len, apr_int32_t flags)
<span class="lineNum">     530 </span>                :            : {
<span class="lineNum">     531 </span>                :            :     off_t nbytes = 0;
<span class="lineNum">     532 </span>                :            :     int rv;
<span class="lineNum">     533 </span>                :            : #if defined(__FreeBSD_version) &amp;&amp; __FreeBSD_version &lt; 460001
<span class="lineNum">     534 </span>                :            :     int i;
<span class="lineNum">     535 </span>                :            : #endif
<span class="lineNum">     536 </span>                :            :     struct sf_hdtr headerstruct;
<span class="lineNum">     537 </span>                :            :     apr_size_t bytes_to_send = *len;
<span class="lineNum">     538 </span>                :            : 
<span class="lineNum">     539 </span>                :            :     /* Ignore flags for now. */
<span class="lineNum">     540 </span>                :            :     flags = 0;
<span class="lineNum">     541 </span>                :            : 
<span class="lineNum">     542 </span>                :            :     if (!hdtr) {
<span class="lineNum">     543 </span>                :            :         hdtr = &amp;no_hdtr;
<span class="lineNum">     544 </span>                :            :     }
<span class="lineNum">     545 </span>                :            : 
<span class="lineNum">     546 </span>                :            : #if defined(__FreeBSD_version) &amp;&amp; __FreeBSD_version &lt; 460001
<span class="lineNum">     547 </span>                :            :     else if (hdtr-&gt;numheaders) {
<span class="lineNum">     548 </span>                :            : 
<span class="lineNum">     549 </span>                :            :         /* On early versions of FreeBSD sendfile, the number of bytes to send 
<span class="lineNum">     550 </span>                :            :          * must include the length of the headers.  Don't look at the man page 
<span class="lineNum">     551 </span>                :            :          * for this :(  Instead, look at the the logic in 
<span class="lineNum">     552 </span>                :            :          * src/sys/kern/uipc_syscalls::sendfile().
<span class="lineNum">     553 </span>                :            :          *
<span class="lineNum">     554 </span>                :            :          * This was fixed in the middle of 4.6-STABLE
<span class="lineNum">     555 </span>                :            :          */
<span class="lineNum">     556 </span>                :            :         for (i = 0; i &lt; hdtr-&gt;numheaders; i++) {
<span class="lineNum">     557 </span>                :            :             bytes_to_send += hdtr-&gt;headers[i].iov_len;
<span class="lineNum">     558 </span>                :            :         }
<span class="lineNum">     559 </span>                :            :     }
<span class="lineNum">     560 </span>                :            : #endif
<span class="lineNum">     561 </span>                :            : 
<span class="lineNum">     562 </span>                :            :     headerstruct.headers = hdtr-&gt;headers;
<span class="lineNum">     563 </span>                :            :     headerstruct.hdr_cnt = hdtr-&gt;numheaders;
<span class="lineNum">     564 </span>                :            :     headerstruct.trailers = hdtr-&gt;trailers;
<span class="lineNum">     565 </span>                :            :     headerstruct.trl_cnt = hdtr-&gt;numtrailers;
<span class="lineNum">     566 </span>                :            : 
<span class="lineNum">     567 </span>                :            :     /* FreeBSD can send the headers/footers as part of the system call */
<span class="lineNum">     568 </span>                :            :     do {
<span class="lineNum">     569 </span>                :            :         if (sock-&gt;options &amp; APR_INCOMPLETE_WRITE) {
<span class="lineNum">     570 </span>                :            :             apr_status_t arv;
<span class="lineNum">     571 </span>                :            :             sock-&gt;options &amp;= ~APR_INCOMPLETE_WRITE;
<span class="lineNum">     572 </span>                :            :             arv = apr_wait_for_io_or_timeout(NULL, sock, 0);
<span class="lineNum">     573 </span>                :            :             if (arv != APR_SUCCESS) {
<span class="lineNum">     574 </span>                :            :                 *len = 0;
<span class="lineNum">     575 </span>                :            :                 return arv;
<span class="lineNum">     576 </span>                :            :             }
<span class="lineNum">     577 </span>                :            :         }
<span class="lineNum">     578 </span>                :            :         if (bytes_to_send) {
<span class="lineNum">     579 </span>                :            :             /* We won't dare call sendfile() if we don't have
<span class="lineNum">     580 </span>                :            :              * header or file bytes to send because bytes_to_send == 0
<span class="lineNum">     581 </span>                :            :              * means send the whole file.
<span class="lineNum">     582 </span>                :            :              */
<span class="lineNum">     583 </span>                :            :             rv = sendfile(file-&gt;filedes, /* file to be sent */
<span class="lineNum">     584 </span>                :            :                           sock-&gt;socketdes, /* socket */
<span class="lineNum">     585 </span>                :            :                           *offset,       /* where in the file to start */
<span class="lineNum">     586 </span>                :            :                           bytes_to_send, /* number of bytes to send */
<span class="lineNum">     587 </span>                :            :                           &amp;headerstruct, /* Headers/footers */
<span class="lineNum">     588 </span>                :            :                           &amp;nbytes,       /* number of bytes written */
<span class="lineNum">     589 </span>                :            :                           flags);        /* undefined, set to 0 */
<span class="lineNum">     590 </span>                :            : 
<span class="lineNum">     591 </span>                :            :             if (rv == -1) {
<span class="lineNum">     592 </span>                :            :                 if (errno == EAGAIN) {
<span class="lineNum">     593 </span>                :            :                     if (sock-&gt;timeout &gt; 0) {
<span class="lineNum">     594 </span>                :            :                         sock-&gt;options |= APR_INCOMPLETE_WRITE;
<span class="lineNum">     595 </span>                :            :                     }
<span class="lineNum">     596 </span>                :            :                     /* FreeBSD's sendfile can return -1/EAGAIN even if it
<span class="lineNum">     597 </span>                :            :                      * sent bytes.  Sanitize the result so we get normal EAGAIN
<span class="lineNum">     598 </span>                :            :                      * semantics w.r.t. bytes sent.
<span class="lineNum">     599 </span>                :            :                      */
<span class="lineNum">     600 </span>                :            :                     if (nbytes) {
<span class="lineNum">     601 </span>                :            :                         /* normal exit for a big file &amp; non-blocking io */
<span class="lineNum">     602 </span>                :            :                         (*len) = nbytes;
<span class="lineNum">     603 </span>                :            :                         return APR_SUCCESS;
<span class="lineNum">     604 </span>                :            :                     }
<span class="lineNum">     605 </span>                :            :                 }
<span class="lineNum">     606 </span>                :            :             }
<span class="lineNum">     607 </span>                :            :             else {       /* rv == 0 (or the kernel is broken) */
<span class="lineNum">     608 </span>                :            :                 if (nbytes == 0) {
<span class="lineNum">     609 </span>                :            :                     /* Most likely the file got smaller after the stat.
<span class="lineNum">     610 </span>                :            :                      * Return an error so the caller can do the Right Thing.
<span class="lineNum">     611 </span>                :            :                      */
<span class="lineNum">     612 </span>                :            :                     (*len) = nbytes;
<span class="lineNum">     613 </span>                :            :                     return APR_EOF;
<span class="lineNum">     614 </span>                :            :                 }
<span class="lineNum">     615 </span>                :            :             }
<span class="lineNum">     616 </span>                :            :         }    
<span class="lineNum">     617 </span>                :            :         else {
<span class="lineNum">     618 </span>                :            :             /* just trailer bytes... use writev()
<span class="lineNum">     619 </span>                :            :              */
<span class="lineNum">     620 </span>                :            :             rv = writev(sock-&gt;socketdes,
<span class="lineNum">     621 </span>                :            :                         hdtr-&gt;trailers,
<span class="lineNum">     622 </span>                :            :                         hdtr-&gt;numtrailers);
<span class="lineNum">     623 </span>                :            :             if (rv &gt; 0) {
<span class="lineNum">     624 </span>                :            :                 nbytes = rv;
<span class="lineNum">     625 </span>                :            :                 rv = 0;
<span class="lineNum">     626 </span>                :            :             }
<span class="lineNum">     627 </span>                :            :             else {
<span class="lineNum">     628 </span>                :            :                 nbytes = 0;
<span class="lineNum">     629 </span>                :            :             }
<span class="lineNum">     630 </span>                :            :         }
<span class="lineNum">     631 </span>                :            :         if ((rv == -1) &amp;&amp; (errno == EAGAIN) 
<span class="lineNum">     632 </span>                :            :                        &amp;&amp; (sock-&gt;timeout &gt; 0)) {
<span class="lineNum">     633 </span>                :            :             apr_status_t arv = apr_wait_for_io_or_timeout(NULL, sock, 0);
<span class="lineNum">     634 </span>                :            :             if (arv != APR_SUCCESS) {
<span class="lineNum">     635 </span>                :            :                 *len = 0;
<span class="lineNum">     636 </span>                :            :                 return arv;
<span class="lineNum">     637 </span>                :            :             }
<span class="lineNum">     638 </span>                :            :         }
<span class="lineNum">     639 </span>                :            :     } while (rv == -1 &amp;&amp; (errno == EINTR || errno == EAGAIN));
<span class="lineNum">     640 </span>                :            : 
<span class="lineNum">     641 </span>                :            :     (*len) = nbytes;
<span class="lineNum">     642 </span>                :            :     if (rv == -1) {
<span class="lineNum">     643 </span>                :            :         return errno;
<span class="lineNum">     644 </span>                :            :     }
<span class="lineNum">     645 </span>                :            :     return APR_SUCCESS;
<span class="lineNum">     646 </span>                :            : }
<span class="lineNum">     647 </span>                :            : 
<span class="lineNum">     648 </span>                :            : #elif defined(__hpux) || defined(__hpux__)
<span class="lineNum">     649 </span>                :            : 
<span class="lineNum">     650 </span>                :            : /* HP cc in ANSI mode defines __hpux; gcc defines __hpux__ */
<span class="lineNum">     651 </span>                :            : 
<span class="lineNum">     652 </span>                :            : /* HP-UX Version 10.30 or greater
<span class="lineNum">     653 </span>                :            :  * (no worries, because we only get here if autoconfiguration found sendfile)
<span class="lineNum">     654 </span>                :            :  */
<span class="lineNum">     655 </span>                :            : 
<span class="lineNum">     656 </span>                :            : /* ssize_t sendfile(int s, int fd, off_t offset, size_t nbytes,
<span class="lineNum">     657 </span>                :            :  *                  const struct iovec *hdtrl, int flags);
<span class="lineNum">     658 </span>                :            :  *
<span class="lineNum">     659 </span>                :            :  * nbytes is the number of bytes to send just from the file; as with FreeBSD, 
<span class="lineNum">     660 </span>                :            :  * if nbytes == 0, the rest of the file (from offset) is sent
<span class="lineNum">     661 </span>                :            :  */
<span class="lineNum">     662 </span>                :            : 
<span class="lineNum">     663 </span>                :            : apr_status_t apr_socket_sendfile(apr_socket_t *sock, apr_file_t *file,
<span class="lineNum">     664 </span>                :            :                                  apr_hdtr_t *hdtr, apr_off_t *offset,
<span class="lineNum">     665 </span>                :            :                                  apr_size_t *len, apr_int32_t flags)
<span class="lineNum">     666 </span>                :            : {
<span class="lineNum">     667 </span>                :            :     int i;
<span class="lineNum">     668 </span>                :            :     apr_ssize_t rc;
<span class="lineNum">     669 </span>                :            :     apr_size_t nbytes = *len, headerlen, trailerlen;
<span class="lineNum">     670 </span>                :            :     struct iovec hdtrarray[2];
<span class="lineNum">     671 </span>                :            :     char *headerbuf, *trailerbuf;
<span class="lineNum">     672 </span>                :            : 
<span class="lineNum">     673 </span>                :            : #if APR_HAS_LARGE_FILES &amp;&amp; defined(HAVE_SENDFILE64)
<span class="lineNum">     674 </span>                :            :     /* later HP-UXes have a sendfile64() */
<span class="lineNum">     675 </span>                :            : #define sendfile sendfile64
<span class="lineNum">     676 </span>                :            :     apr_off_t off = *offset;
<span class="lineNum">     677 </span>                :            : 
<span class="lineNum">     678 </span>                :            : #elif APR_HAS_LARGE_FILES &amp;&amp; SIZEOF_OFF_T == 4
<span class="lineNum">     679 </span>                :            :     /* HP-UX 11.00 doesn't have a sendfile64(): fail if trying to send
<span class="lineNum">     680 </span>                :            :      * past the 2Gb limit */
<span class="lineNum">     681 </span>                :            :     off_t off;
<span class="lineNum">     682 </span>                :            : 
<span class="lineNum">     683 </span>                :            :     if ((apr_int64_t)*offset + *len &gt; INT_MAX) {
<span class="lineNum">     684 </span>                :            :         return EINVAL;
<span class="lineNum">     685 </span>                :            :     }
<span class="lineNum">     686 </span>                :            :     off = *offset;
<span class="lineNum">     687 </span>                :            : #else
<span class="lineNum">     688 </span>                :            :     apr_off_t off = *offset;
<span class="lineNum">     689 </span>                :            : #endif
<span class="lineNum">     690 </span>                :            : 
<span class="lineNum">     691 </span>                :            :     if (!hdtr) {
<span class="lineNum">     692 </span>                :            :         hdtr = &amp;no_hdtr;
<span class="lineNum">     693 </span>                :            :     }
<span class="lineNum">     694 </span>                :            : 
<span class="lineNum">     695 </span>                :            :     /* Ignore flags for now. */
<span class="lineNum">     696 </span>                :            :     flags = 0;
<span class="lineNum">     697 </span>                :            : 
<span class="lineNum">     698 </span>                :            :     /* HP-UX can only send one header iovec and one footer iovec; try to
<span class="lineNum">     699 </span>                :            :      * only allocate storage to combine input iovecs when we really have to
<span class="lineNum">     700 </span>                :            :      */
<span class="lineNum">     701 </span>                :            : 
<span class="lineNum">     702 </span>                :            :     switch(hdtr-&gt;numheaders) {
<span class="lineNum">     703 </span>                :            :     case 0:
<span class="lineNum">     704 </span>                :            :         hdtrarray[0].iov_base = NULL;
<span class="lineNum">     705 </span>                :            :         hdtrarray[0].iov_len = 0;
<span class="lineNum">     706 </span>                :            :         break;
<span class="lineNum">     707 </span>                :            :     case 1:
<span class="lineNum">     708 </span>                :            :         hdtrarray[0] = hdtr-&gt;headers[0];
<span class="lineNum">     709 </span>                :            :         break;
<span class="lineNum">     710 </span>                :            :     default:
<span class="lineNum">     711 </span>                :            :         headerlen = 0;
<span class="lineNum">     712 </span>                :            :         for (i = 0; i &lt; hdtr-&gt;numheaders; i++) {
<span class="lineNum">     713 </span>                :            :             headerlen += hdtr-&gt;headers[i].iov_len;
<span class="lineNum">     714 </span>                :            :         }  
<span class="lineNum">     715 </span>                :            : 
<span class="lineNum">     716 </span>                :            :         /* XXX:  BUHHH? wow, what a memory leak! */
<span class="lineNum">     717 </span>                :            :         headerbuf = hdtrarray[0].iov_base = apr_palloc(sock-&gt;pool, headerlen);
<span class="lineNum">     718 </span>                :            :         hdtrarray[0].iov_len = headerlen;
<span class="lineNum">     719 </span>                :            : 
<span class="lineNum">     720 </span>                :            :         for (i = 0; i &lt; hdtr-&gt;numheaders; i++) {
<span class="lineNum">     721 </span>                :            :             memcpy(headerbuf, hdtr-&gt;headers[i].iov_base,
<span class="lineNum">     722 </span>                :            :                    hdtr-&gt;headers[i].iov_len);
<span class="lineNum">     723 </span>                :            :             headerbuf += hdtr-&gt;headers[i].iov_len;
<span class="lineNum">     724 </span>                :            :         }
<span class="lineNum">     725 </span>                :            :     }
<span class="lineNum">     726 </span>                :            : 
<span class="lineNum">     727 </span>                :            :     switch(hdtr-&gt;numtrailers) {
<span class="lineNum">     728 </span>                :            :     case 0:
<span class="lineNum">     729 </span>                :            :         hdtrarray[1].iov_base = NULL;
<span class="lineNum">     730 </span>                :            :         hdtrarray[1].iov_len = 0;
<span class="lineNum">     731 </span>                :            :         break;
<span class="lineNum">     732 </span>                :            :     case 1:
<span class="lineNum">     733 </span>                :            :         hdtrarray[1] = hdtr-&gt;trailers[0];
<span class="lineNum">     734 </span>                :            :         break;
<span class="lineNum">     735 </span>                :            :     default:
<span class="lineNum">     736 </span>                :            :         trailerlen = 0;
<span class="lineNum">     737 </span>                :            :         for (i = 0; i &lt; hdtr-&gt;numtrailers; i++) {
<span class="lineNum">     738 </span>                :            :             trailerlen += hdtr-&gt;trailers[i].iov_len;
<span class="lineNum">     739 </span>                :            :         }
<span class="lineNum">     740 </span>                :            : 
<span class="lineNum">     741 </span>                :            :         /* XXX:  BUHHH? wow, what a memory leak! */
<span class="lineNum">     742 </span>                :            :         trailerbuf = hdtrarray[1].iov_base = apr_palloc(sock-&gt;pool, trailerlen);
<span class="lineNum">     743 </span>                :            :         hdtrarray[1].iov_len = trailerlen;
<span class="lineNum">     744 </span>                :            : 
<span class="lineNum">     745 </span>                :            :         for (i = 0; i &lt; hdtr-&gt;numtrailers; i++) {
<span class="lineNum">     746 </span>                :            :             memcpy(trailerbuf, hdtr-&gt;trailers[i].iov_base,
<span class="lineNum">     747 </span>                :            :                    hdtr-&gt;trailers[i].iov_len);
<span class="lineNum">     748 </span>                :            :             trailerbuf += hdtr-&gt;trailers[i].iov_len;
<span class="lineNum">     749 </span>                :            :         }
<span class="lineNum">     750 </span>                :            :     }
<span class="lineNum">     751 </span>                :            : 
<span class="lineNum">     752 </span>                :            :     do {
<span class="lineNum">     753 </span>                :            :         if (nbytes) {       /* any bytes to send from the file? */
<span class="lineNum">     754 </span>                :            :             rc = sendfile(sock-&gt;socketdes,      /* socket  */
<span class="lineNum">     755 </span>                :            :                           file-&gt;filedes,        /* file descriptor to send */
<span class="lineNum">     756 </span>                :            :                           off,                  /* where in the file to start */
<span class="lineNum">     757 </span>                :            :                           nbytes,               /* number of bytes to send from file */
<span class="lineNum">     758 </span>                :            :                           hdtrarray,            /* Headers/footers */
<span class="lineNum">     759 </span>                :            :                           flags);               /* undefined, set to 0 */
<span class="lineNum">     760 </span>                :            :         }
<span class="lineNum">     761 </span>                :            :         else {              /* we can't call sendfile() with no bytes to send from the file */
<span class="lineNum">     762 </span>                :            :             rc = writev(sock-&gt;socketdes, hdtrarray, 2);
<span class="lineNum">     763 </span>                :            :         }
<span class="lineNum">     764 </span>                :            :     } while (rc == -1 &amp;&amp; errno == EINTR);
<span class="lineNum">     765 </span>                :            : 
<span class="lineNum">     766 </span>                :            :     while ((rc == -1) &amp;&amp; (errno == EAGAIN || errno == EWOULDBLOCK) 
<span class="lineNum">     767 </span>                :            :                       &amp;&amp; (sock-&gt;timeout &gt; 0)) {
<span class="lineNum">     768 </span>                :            :         apr_status_t arv = apr_wait_for_io_or_timeout(NULL, sock, 0);
<span class="lineNum">     769 </span>                :            : 
<span class="lineNum">     770 </span>                :            :         if (arv != APR_SUCCESS) {
<span class="lineNum">     771 </span>                :            :             *len = 0;
<span class="lineNum">     772 </span>                :            :             return arv;
<span class="lineNum">     773 </span>                :            :         }
<span class="lineNum">     774 </span>                :            :         else {
<span class="lineNum">     775 </span>                :            :             do {
<span class="lineNum">     776 </span>                :            :                 if (nbytes) {
<span class="lineNum">     777 </span>                :            :                     rc = sendfile(sock-&gt;socketdes,    /* socket  */
<span class="lineNum">     778 </span>                :            :                                   file-&gt;filedes,      /* file descriptor to send */
<span class="lineNum">     779 </span>                :            :                                   off,                /* where in the file to start */
<span class="lineNum">     780 </span>                :            :                                   nbytes,             /* number of bytes to send from file */
<span class="lineNum">     781 </span>                :            :                                   hdtrarray,          /* Headers/footers */
<span class="lineNum">     782 </span>                :            :                                   flags);             /* undefined, set to 0 */
<span class="lineNum">     783 </span>                :            :                 }
<span class="lineNum">     784 </span>                :            :                 else {      /* we can't call sendfile() with no bytes to send from the file */
<span class="lineNum">     785 </span>                :            :                     rc = writev(sock-&gt;socketdes, hdtrarray, 2);
<span class="lineNum">     786 </span>                :            :                 }
<span class="lineNum">     787 </span>                :            :             } while (rc == -1 &amp;&amp; errno == EINTR);
<span class="lineNum">     788 </span>                :            :         }
<span class="lineNum">     789 </span>                :            :     }
<span class="lineNum">     790 </span>                :            : 
<span class="lineNum">     791 </span>                :            :     if (rc == -1) {
<span class="lineNum">     792 </span>                :            :         *len = 0;
<span class="lineNum">     793 </span>                :            :         return errno;
<span class="lineNum">     794 </span>                :            :     }
<span class="lineNum">     795 </span>                :            : 
<span class="lineNum">     796 </span>                :            :     /* Set len to the number of bytes written */
<span class="lineNum">     797 </span>                :            :     *len = rc;
<span class="lineNum">     798 </span>                :            :     return APR_SUCCESS;
<span class="lineNum">     799 </span>                :            : }
<span class="lineNum">     800 </span>                :            : #elif defined(_AIX) || defined(__MVS__)
<span class="lineNum">     801 </span>                :            : /* AIX and OS/390 have the same send_file() interface.
<span class="lineNum">     802 </span>                :            :  *
<span class="lineNum">     803 </span>                :            :  * subtle differences:
<span class="lineNum">     804 </span>                :            :  *   AIX doesn't update the file ptr but OS/390 does
<span class="lineNum">     805 </span>                :            :  *
<span class="lineNum">     806 </span>                :            :  * availability (correctly determined by autoconf):
<span class="lineNum">     807 </span>                :            :  *
<span class="lineNum">     808 </span>                :            :  * AIX -  version 4.3.2 with APAR IX85388, or version 4.3.3 and above
<span class="lineNum">     809 </span>                :            :  * OS/390 - V2R7 and above
<span class="lineNum">     810 </span>                :            :  */
<span class="lineNum">     811 </span>                :            : apr_status_t apr_socket_sendfile(apr_socket_t * sock, apr_file_t * file,
<span class="lineNum">     812 </span>                :            :                                  apr_hdtr_t * hdtr, apr_off_t * offset,
<span class="lineNum">     813 </span>                :            :                                  apr_size_t * len, apr_int32_t flags)
<span class="lineNum">     814 </span>                :            : {
<span class="lineNum">     815 </span>                :            :     int i, ptr, rv = 0;
<span class="lineNum">     816 </span>                :            :     void * hbuf=NULL, * tbuf=NULL;
<span class="lineNum">     817 </span>                :            :     apr_status_t arv;
<span class="lineNum">     818 </span>                :            :     struct sf_parms parms;
<span class="lineNum">     819 </span>                :            : 
<span class="lineNum">     820 </span>                :            :     if (!hdtr) {
<span class="lineNum">     821 </span>                :            :         hdtr = &amp;no_hdtr;
<span class="lineNum">     822 </span>                :            :     }
<span class="lineNum">     823 </span>                :            : 
<span class="lineNum">     824 </span>                :            :     /* Ignore flags for now. */
<span class="lineNum">     825 </span>                :            :     flags = 0;
<span class="lineNum">     826 </span>                :            : 
<span class="lineNum">     827 </span>                :            :     /* word to the wise: by default, AIX stores files sent by send_file()
<span class="lineNum">     828 </span>                :            :      * in the network buffer cache...  there are supposedly scenarios
<span class="lineNum">     829 </span>                :            :      * where the most recent copy of the file won't be sent, but I can't
<span class="lineNum">     830 </span>                :            :      * recreate the potential problem, perhaps because of the way we
<span class="lineNum">     831 </span>                :            :      * use send_file()...  if you suspect such a problem, try turning
<span class="lineNum">     832 </span>                :            :      * on the SF_SYNC_CACHE flag
<span class="lineNum">     833 </span>                :            :      */
<span class="lineNum">     834 </span>                :            : 
<span class="lineNum">     835 </span>                :            :     /* AIX can also send the headers/footers as part of the system call */
<span class="lineNum">     836 </span>                :            :     parms.header_length = 0;
<span class="lineNum">     837 </span>                :            :     if (hdtr &amp;&amp; hdtr-&gt;numheaders) {
<span class="lineNum">     838 </span>                :            :         if (hdtr-&gt;numheaders == 1) {
<span class="lineNum">     839 </span>                :            :             parms.header_data = hdtr-&gt;headers[0].iov_base;
<span class="lineNum">     840 </span>                :            :             parms.header_length = hdtr-&gt;headers[0].iov_len;
<span class="lineNum">     841 </span>                :            :         }
<span class="lineNum">     842 </span>                :            :         else {
<span class="lineNum">     843 </span>                :            :             for (i = 0; i &lt; hdtr-&gt;numheaders; i++) {
<span class="lineNum">     844 </span>                :            :                 parms.header_length += hdtr-&gt;headers[i].iov_len;
<span class="lineNum">     845 </span>                :            :             }
<span class="lineNum">     846 </span>                :            : #if 0
<span class="lineNum">     847 </span>                :            :             /* Keepalives make apr_palloc a bad idea */
<span class="lineNum">     848 </span>                :            :             hbuf = malloc(parms.header_length);
<span class="lineNum">     849 </span>                :            : #else
<span class="lineNum">     850 </span>                :            :             /* but headers are small, so maybe we can hold on to the
<span class="lineNum">     851 </span>                :            :              * memory for the life of the socket...
<span class="lineNum">     852 </span>                :            :              */
<span class="lineNum">     853 </span>                :            :             hbuf = apr_palloc(sock-&gt;pool, parms.header_length);
<span class="lineNum">     854 </span>                :            : #endif
<span class="lineNum">     855 </span>                :            :             ptr = 0;
<span class="lineNum">     856 </span>                :            :             for (i = 0; i &lt; hdtr-&gt;numheaders; i++) {
<span class="lineNum">     857 </span>                :            :                 memcpy((char *)hbuf + ptr, hdtr-&gt;headers[i].iov_base,
<span class="lineNum">     858 </span>                :            :                        hdtr-&gt;headers[i].iov_len);
<span class="lineNum">     859 </span>                :            :                 ptr += hdtr-&gt;headers[i].iov_len;
<span class="lineNum">     860 </span>                :            :             }
<span class="lineNum">     861 </span>                :            :             parms.header_data = hbuf;
<span class="lineNum">     862 </span>                :            :         }
<span class="lineNum">     863 </span>                :            :     }
<span class="lineNum">     864 </span>                :            :     else parms.header_data = NULL;
<span class="lineNum">     865 </span>                :            :     parms.trailer_length = 0;
<span class="lineNum">     866 </span>                :            :     if (hdtr &amp;&amp; hdtr-&gt;numtrailers) {
<span class="lineNum">     867 </span>                :            :         if (hdtr-&gt;numtrailers == 1) {
<span class="lineNum">     868 </span>                :            :             parms.trailer_data = hdtr-&gt;trailers[0].iov_base;
<span class="lineNum">     869 </span>                :            :             parms.trailer_length = hdtr-&gt;trailers[0].iov_len;
<span class="lineNum">     870 </span>                :            :         }
<span class="lineNum">     871 </span>                :            :         else {
<span class="lineNum">     872 </span>                :            :             for (i = 0; i &lt; hdtr-&gt;numtrailers; i++) {
<span class="lineNum">     873 </span>                :            :                 parms.trailer_length += hdtr-&gt;trailers[i].iov_len;
<span class="lineNum">     874 </span>                :            :             }
<span class="lineNum">     875 </span>                :            : #if 0
<span class="lineNum">     876 </span>                :            :             /* Keepalives make apr_palloc a bad idea */
<span class="lineNum">     877 </span>                :            :             tbuf = malloc(parms.trailer_length);
<span class="lineNum">     878 </span>                :            : #else
<span class="lineNum">     879 </span>                :            :             tbuf = apr_palloc(sock-&gt;pool, parms.trailer_length);
<span class="lineNum">     880 </span>                :            : #endif
<span class="lineNum">     881 </span>                :            :             ptr = 0;
<span class="lineNum">     882 </span>                :            :             for (i = 0; i &lt; hdtr-&gt;numtrailers; i++) {
<span class="lineNum">     883 </span>                :            :                 memcpy((char *)tbuf + ptr, hdtr-&gt;trailers[i].iov_base,
<span class="lineNum">     884 </span>                :            :                        hdtr-&gt;trailers[i].iov_len);
<span class="lineNum">     885 </span>                :            :                 ptr += hdtr-&gt;trailers[i].iov_len;
<span class="lineNum">     886 </span>                :            :             }
<span class="lineNum">     887 </span>                :            :             parms.trailer_data = tbuf;
<span class="lineNum">     888 </span>                :            :         }
<span class="lineNum">     889 </span>                :            :     }
<span class="lineNum">     890 </span>                :            :     else {
<span class="lineNum">     891 </span>                :            :         parms.trailer_data = NULL;
<span class="lineNum">     892 </span>                :            :     }
<span class="lineNum">     893 </span>                :            : 
<span class="lineNum">     894 </span>                :            :     /* Whew! Headers and trailers set up. Now for the file data */
<span class="lineNum">     895 </span>                :            : 
<span class="lineNum">     896 </span>                :            :     parms.file_descriptor = file-&gt;filedes;
<span class="lineNum">     897 </span>                :            :     parms.file_offset = *offset;
<span class="lineNum">     898 </span>                :            :     parms.file_bytes = *len;
<span class="lineNum">     899 </span>                :            : 
<span class="lineNum">     900 </span>                :            :     /* O.K. All set up now. Let's go to town */
<span class="lineNum">     901 </span>                :            : 
<span class="lineNum">     902 </span>                :            :     if (sock-&gt;options &amp; APR_INCOMPLETE_WRITE) {
<span class="lineNum">     903 </span>                :            :         sock-&gt;options &amp;= ~APR_INCOMPLETE_WRITE;
<span class="lineNum">     904 </span>                :            :         goto do_select;
<span class="lineNum">     905 </span>                :            :     }
<span class="lineNum">     906 </span>                :            : 
<span class="lineNum">     907 </span>                :            :     do {
<span class="lineNum">     908 </span>                :            :         rv = send_file(&amp;(sock-&gt;socketdes), /* socket */
<span class="lineNum">     909 </span>                :            :                        &amp;(parms),           /* all data */
<span class="lineNum">     910 </span>                :            :                        flags);             /* flags */
<span class="lineNum">     911 </span>                :            :     } while (rv == -1 &amp;&amp; errno == EINTR);
<span class="lineNum">     912 </span>                :            : 
<span class="lineNum">     913 </span>                :            :     while ((rv == -1) &amp;&amp; (errno == EAGAIN || errno == EWOULDBLOCK) 
<span class="lineNum">     914 </span>                :            :                       &amp;&amp; (sock-&gt;timeout &gt; 0)) {
<span class="lineNum">     915 </span>                :            : do_select:
<span class="lineNum">     916 </span>                :            :         arv = apr_wait_for_io_or_timeout(NULL, sock, 0);
<span class="lineNum">     917 </span>                :            :         if (arv != APR_SUCCESS) {
<span class="lineNum">     918 </span>                :            :             *len = 0;
<span class="lineNum">     919 </span>                :            :             return arv;
<span class="lineNum">     920 </span>                :            :         }
<span class="lineNum">     921 </span>                :            :         else {
<span class="lineNum">     922 </span>                :            :             do {
<span class="lineNum">     923 </span>                :            :                 rv = send_file(&amp;(sock-&gt;socketdes), /* socket */
<span class="lineNum">     924 </span>                :            :                                &amp;(parms),           /* all data */
<span class="lineNum">     925 </span>                :            :                                flags);             /* flags */
<span class="lineNum">     926 </span>                :            :             } while (rv == -1 &amp;&amp; errno == EINTR);
<span class="lineNum">     927 </span>                :            :         }
<span class="lineNum">     928 </span>                :            :     }
<span class="lineNum">     929 </span>                :            : 
<span class="lineNum">     930 </span>                :            :     (*len) = parms.bytes_sent;
<span class="lineNum">     931 </span>                :            : 
<span class="lineNum">     932 </span>                :            : #if 0
<span class="lineNum">     933 </span>                :            :     /* Clean up after ourselves */
<span class="lineNum">     934 </span>                :            :     if(hbuf) free(hbuf);
<span class="lineNum">     935 </span>                :            :     if(tbuf) free(tbuf);
<span class="lineNum">     936 </span>                :            : #endif
<span class="lineNum">     937 </span>                :            : 
<span class="lineNum">     938 </span>                :            :     if (rv == -1) {
<span class="lineNum">     939 </span>                :            :         return errno;
<span class="lineNum">     940 </span>                :            :     }
<span class="lineNum">     941 </span>                :            : 
<span class="lineNum">     942 </span>                :            :     if ((sock-&gt;timeout &gt; 0)
<span class="lineNum">     943 </span>                :            :           &amp;&amp; (parms.bytes_sent 
<span class="lineNum">     944 </span>                :            :                 &lt; (parms.file_bytes + parms.header_length + parms.trailer_length))) {
<span class="lineNum">     945 </span>                :            :         sock-&gt;options |= APR_INCOMPLETE_WRITE;
<span class="lineNum">     946 </span>                :            :     }
<span class="lineNum">     947 </span>                :            : 
<span class="lineNum">     948 </span>                :            :     return APR_SUCCESS;
<span class="lineNum">     949 </span>                :            : }
<span class="lineNum">     950 </span>                :            : #elif defined(__osf__) &amp;&amp; defined (__alpha)
<span class="lineNum">     951 </span>                :            : /* Tru64's sendfile implementation doesn't work, and we need to make sure that
<span class="lineNum">     952 </span>                :            :  * we don't use it until it is fixed.  If it is used as it is now, it will
<span class="lineNum">     953 </span>                :            :  * hang the machine and the only way to fix it is a reboot.
<span class="lineNum">     954 </span>                :            :  */
<span class="lineNum">     955 </span>                :            : #elif defined(HAVE_SENDFILEV)
<span class="lineNum">     956 </span>                :            : /* Solaris 8's sendfilev() interface 
<span class="lineNum">     957 </span>                :            :  *
<span class="lineNum">     958 </span>                :            :  * SFV_FD_SELF refers to our memory space.
<span class="lineNum">     959 </span>                :            :  *
<span class="lineNum">     960 </span>                :            :  * Required Sparc patches (or newer):
<span class="lineNum">     961 </span>                :            :  * 111297-01, 108528-09, 109472-06, 109234-03, 108995-02, 111295-01, 109025-03,
<span class="lineNum">     962 </span>                :            :  * 108991-13
<span class="lineNum">     963 </span>                :            :  * Required x86 patches (or newer):
<span class="lineNum">     964 </span>                :            :  * 111298-01, 108529-09, 109473-06, 109235-04, 108996-02, 111296-01, 109026-04,
<span class="lineNum">     965 </span>                :            :  * 108992-13
<span class="lineNum">     966 </span>                :            :  */
<span class="lineNum">     967 </span>                :            : 
<span class="lineNum">     968 </span>                :            : #if APR_HAS_LARGE_FILES &amp;&amp; defined(HAVE_SENDFILEV64)
<span class="lineNum">     969 </span>                :            : #define sendfilevec_t sendfilevec64_t
<span class="lineNum">     970 </span>                :            : #define sendfilev sendfilev64
<span class="lineNum">     971 </span>                :            : #endif
<span class="lineNum">     972 </span>                :            : 
<span class="lineNum">     973 </span>                :            : apr_status_t apr_socket_sendfile(apr_socket_t *sock, apr_file_t *file,
<span class="lineNum">     974 </span>                :            :                                  apr_hdtr_t *hdtr, apr_off_t *offset,
<span class="lineNum">     975 </span>                :            :                                  apr_size_t *len, apr_int32_t flags)
<span class="lineNum">     976 </span>                :            : {
<span class="lineNum">     977 </span>                :            :     apr_status_t rv, arv;
<span class="lineNum">     978 </span>                :            :     apr_size_t nbytes;
<span class="lineNum">     979 </span>                :            :     sendfilevec_t *sfv;
<span class="lineNum">     980 </span>                :            :     int vecs, curvec, i, repeat;
<span class="lineNum">     981 </span>                :            :     apr_size_t requested_len = 0;
<span class="lineNum">     982 </span>                :            : 
<span class="lineNum">     983 </span>                :            :     if (!hdtr) {
<span class="lineNum">     984 </span>                :            :         hdtr = &amp;no_hdtr;
<span class="lineNum">     985 </span>                :            :     }
<span class="lineNum">     986 </span>                :            : 
<span class="lineNum">     987 </span>                :            :     /* Ignore flags for now. */
<span class="lineNum">     988 </span>                :            :     flags = 0;
<span class="lineNum">     989 </span>                :            : 
<span class="lineNum">     990 </span>                :            :     /* Calculate how much space we need. */
<span class="lineNum">     991 </span>                :            :     vecs = hdtr-&gt;numheaders + hdtr-&gt;numtrailers + 1;
<span class="lineNum">     992 </span>                :            :     sfv = apr_palloc(sock-&gt;pool, sizeof(sendfilevec_t) * vecs);
<span class="lineNum">     993 </span>                :            : 
<span class="lineNum">     994 </span>                :            :     curvec = 0;
<span class="lineNum">     995 </span>                :            : 
<span class="lineNum">     996 </span>                :            :     /* Add the headers */
<span class="lineNum">     997 </span>                :            :     for (i = 0; i &lt; hdtr-&gt;numheaders; i++, curvec++) {
<span class="lineNum">     998 </span>                :            :         sfv[curvec].sfv_fd = SFV_FD_SELF;
<span class="lineNum">     999 </span>                :            :         sfv[curvec].sfv_flag = 0;
<span class="lineNum">    1000 </span>                :            :         /* Cast to unsigned long to prevent sign extension of the
<span class="lineNum">    1001 </span>                :            :          * pointer value for the LFS case; see PR 39463. */
<span class="lineNum">    1002 </span>                :            :         sfv[curvec].sfv_off = (unsigned long)hdtr-&gt;headers[i].iov_base;
<span class="lineNum">    1003 </span>                :            :         sfv[curvec].sfv_len = hdtr-&gt;headers[i].iov_len;
<span class="lineNum">    1004 </span>                :            :         requested_len += sfv[curvec].sfv_len;
<span class="lineNum">    1005 </span>                :            :     }
<span class="lineNum">    1006 </span>                :            : 
<span class="lineNum">    1007 </span>                :            :     /* If the len is 0, we skip the file. */
<span class="lineNum">    1008 </span>                :            :     if (*len)
<span class="lineNum">    1009 </span>                :            :     {
<span class="lineNum">    1010 </span>                :            :         sfv[curvec].sfv_fd = file-&gt;filedes;
<span class="lineNum">    1011 </span>                :            :         sfv[curvec].sfv_flag = 0;
<span class="lineNum">    1012 </span>                :            :         sfv[curvec].sfv_off = *offset;
<span class="lineNum">    1013 </span>                :            :         sfv[curvec].sfv_len = *len; 
<span class="lineNum">    1014 </span>                :            :         requested_len += sfv[curvec].sfv_len;
<span class="lineNum">    1015 </span>                :            : 
<span class="lineNum">    1016 </span>                :            :         curvec++;
<span class="lineNum">    1017 </span>                :            :     }
<span class="lineNum">    1018 </span>                :            :     else {
<span class="lineNum">    1019 </span>                :            :         vecs--;
<span class="lineNum">    1020 </span>                :            :     }
<span class="lineNum">    1021 </span>                :            : 
<span class="lineNum">    1022 </span>                :            :     /* Add the footers */
<span class="lineNum">    1023 </span>                :            :     for (i = 0; i &lt; hdtr-&gt;numtrailers; i++, curvec++) {
<span class="lineNum">    1024 </span>                :            :         sfv[curvec].sfv_fd = SFV_FD_SELF;
<span class="lineNum">    1025 </span>                :            :         sfv[curvec].sfv_flag = 0;
<span class="lineNum">    1026 </span>                :            :         sfv[curvec].sfv_off = (unsigned long)hdtr-&gt;trailers[i].iov_base;
<span class="lineNum">    1027 </span>                :            :         sfv[curvec].sfv_len = hdtr-&gt;trailers[i].iov_len;
<span class="lineNum">    1028 </span>                :            :         requested_len += sfv[curvec].sfv_len;
<span class="lineNum">    1029 </span>                :            :     }
<span class="lineNum">    1030 </span>                :            : 
<span class="lineNum">    1031 </span>                :            :     /* If the last write couldn't send all the requested data,
<span class="lineNum">    1032 </span>                :            :      * wait for the socket to become writable before proceeding
<span class="lineNum">    1033 </span>                :            :      */
<span class="lineNum">    1034 </span>                :            :     if (sock-&gt;options &amp; APR_INCOMPLETE_WRITE) {
<span class="lineNum">    1035 </span>                :            :         sock-&gt;options &amp;= ~APR_INCOMPLETE_WRITE;
<span class="lineNum">    1036 </span>                :            :         arv = apr_wait_for_io_or_timeout(NULL, sock, 0);
<span class="lineNum">    1037 </span>                :            :         if (arv != APR_SUCCESS) {
<span class="lineNum">    1038 </span>                :            :             *len = 0;
<span class="lineNum">    1039 </span>                :            :             return arv;
<span class="lineNum">    1040 </span>                :            :         }
<span class="lineNum">    1041 </span>                :            :     }
<span class="lineNum">    1042 </span>                :            :  
<span class="lineNum">    1043 </span>                :            :     /* Actually do the sendfilev
<span class="lineNum">    1044 </span>                :            :      *
<span class="lineNum">    1045 </span>                :            :      * Solaris may return -1/EAGAIN even if it sent bytes on a non-block sock.
<span class="lineNum">    1046 </span>                :            :      *
<span class="lineNum">    1047 </span>                :            :      * If no bytes were originally sent (nbytes == 0) and we are on a TIMEOUT 
<span class="lineNum">    1048 </span>                :            :      * socket (which as far as the OS is concerned is a non-blocking socket), 
<span class="lineNum">    1049 </span>                :            :      * we want to retry after waiting for the other side to read the data (as 
<span class="lineNum">    1050 </span>                :            :      * determined by poll).  Once it is clear to send, we want to retry
<span class="lineNum">    1051 </span>                :            :      * sending the sendfilevec_t once more.
<span class="lineNum">    1052 </span>                :            :      */
<span class="lineNum">    1053 </span>                :            :     arv = 0;
<span class="lineNum">    1054 </span>                :            :     do {
<span class="lineNum">    1055 </span>                :            :         /* Clear out the repeat */
<span class="lineNum">    1056 </span>                :            :         repeat = 0;
<span class="lineNum">    1057 </span>                :            : 
<span class="lineNum">    1058 </span>                :            :         /* socket, vecs, number of vecs, bytes written */
<span class="lineNum">    1059 </span>                :            :         rv = sendfilev(sock-&gt;socketdes, sfv, vecs, &amp;nbytes);
<span class="lineNum">    1060 </span>                :            : 
<span class="lineNum">    1061 </span>                :            :         if (rv == -1 &amp;&amp; errno == EAGAIN) {
<span class="lineNum">    1062 </span>                :            :             if (nbytes) {
<span class="lineNum">    1063 </span>                :            :                 rv = 0;
<span class="lineNum">    1064 </span>                :            :             }
<span class="lineNum">    1065 </span>                :            :             else if (!arv &amp;&amp; (sock-&gt;timeout &gt; 0)) {
<span class="lineNum">    1066 </span>                :            :                 apr_status_t t = apr_wait_for_io_or_timeout(NULL, sock, 0);
<span class="lineNum">    1067 </span>                :            : 
<span class="lineNum">    1068 </span>                :            :                 if (t != APR_SUCCESS) {
<span class="lineNum">    1069 </span>                :            :                     *len = 0;
<span class="lineNum">    1070 </span>                :            :                     return t;
<span class="lineNum">    1071 </span>                :            :                 }
<span class="lineNum">    1072 </span>                :            : 
<span class="lineNum">    1073 </span>                :            :                 arv = 1; 
<span class="lineNum">    1074 </span>                :            :                 repeat = 1;
<span class="lineNum">    1075 </span>                :            :             }
<span class="lineNum">    1076 </span>                :            :         }
<span class="lineNum">    1077 </span>                :            :     } while ((rv == -1 &amp;&amp; errno == EINTR) || repeat);
<span class="lineNum">    1078 </span>                :            : 
<span class="lineNum">    1079 </span>                :            :     if (rv == -1) {
<span class="lineNum">    1080 </span>                :            :         *len = 0;
<span class="lineNum">    1081 </span>                :            :         return errno;
<span class="lineNum">    1082 </span>                :            :     }
<span class="lineNum">    1083 </span>                :            : 
<span class="lineNum">    1084 </span>                :            :     /* Update how much we sent */
<span class="lineNum">    1085 </span>                :            :     *len = nbytes;
<span class="lineNum">    1086 </span>                :            : 
<span class="lineNum">    1087 </span>                :            :     if (nbytes == 0) {
<span class="lineNum">    1088 </span>                :            :         /* Most likely the file got smaller after the stat.
<span class="lineNum">    1089 </span>                :            :          * Return an error so the caller can do the Right Thing.
<span class="lineNum">    1090 </span>                :            :          */
<span class="lineNum">    1091 </span>                :            :         return APR_EOF;
<span class="lineNum">    1092 </span>                :            :     }
<span class="lineNum">    1093 </span>                :            : 
<span class="lineNum">    1094 </span>                :            :     if ((sock-&gt;timeout &gt; 0) &amp;&amp; (*len &lt; requested_len)) {
<span class="lineNum">    1095 </span>                :            :         sock-&gt;options |= APR_INCOMPLETE_WRITE;
<span class="lineNum">    1096 </span>                :            :     }
<span class="lineNum">    1097 </span>                :            :     return APR_SUCCESS;
<span class="lineNum">    1098 </span>                :            : }
<span class="lineNum">    1099 </span>                :            : #else
<span class="lineNum">    1100 </span>                :            : #error APR has detected sendfile on your system, but nobody has written a
<span class="lineNum">    1101 </span>                :            : #error version of it for APR yet.  To get past this, either write 
<span class="lineNum">    1102 </span>                :            : #error apr_socket_sendfile or change APR_HAS_SENDFILE in apr.h to 0.
<span class="lineNum">    1103 </span>                :            : #endif /* __linux__, __FreeBSD__, __DragonFly__, __HPUX__, _AIX, __MVS__,
<span class="lineNum">    1104 </span>                :            :           Tru64/OSF1 */
<span class="lineNum">    1105 </span>                :            : 
<span class="lineNum">    1106 </span>                :            : #endif /* APR_HAS_SENDFILE */
</pre>
      </td>
    </tr>
  </table>
  <br>

  <table width="100%" border=0 cellspacing=0 cellpadding=0>
    <tr><td class="ruler"><img src="../../glass.png" width=3 height=3 alt=""></td></tr>
    <tr><td class="versionInfo">Generated by: <a href="http://ltp.sourceforge.net/coverage/lcov.php" target="_parent">LCOV version 1.9</a></td></tr>
  </table>
  <br>

</body>
</html>
